Having googled a bit this link may be helpful. Calculate percentages with Flux | InfluxDB Cloud (TSM) Documentation.
Thank you, I already found that site a couple days ago but couldnāt figure out how to do it like described there.
Iāll have another look and see if I can understand now.
With flux being deprecated, do you know what the recommended method of querying in Grafana will be?
I honestly donāt know. In influx I go in my bucket, check my datapoint and click on script builder.
Then I have this code:
from(bucket: "boden-wz")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "monstera")
|> filter(fn: (r) => r["_field"] == "value")
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> yield(name: "mean")
Thatāll just copy-paste in grafana.
Tbh Iām totally new to all this. I just followed some tutorials and failed around.
My target was to play through a tool chain to see if I can do it.
So I hope my answer helps a bit, I wish I could tell more.
Ok so in influx it makes sense I guess. I just donāt know how to name the value, everything I tried so far, failed.
|> map(fn: (r) => ({ r with _value: 100.0 * (2850.0 - "_field") / (2850.0 - 1250.0) }))
Where did you put that? Before the aggregateWindow or after it?
Doesn't the yield at the end name it?
You would save influx a little time by using
{ r with _value: 0.0625 * (2850.0 - "_field")}
Yes, I put it right before that line.
Itās also just a string,:
|> yield(name: "mean")
Just like that? Not the map before it?
|> map(fn: (r) => ({ r with _value: 0.0625 * (2850.0 - "_field")})
It doesnāt matter btw if itās field or mean, the error stays the same, itās expecting an float but I have no idea what language that is, so I donāt know how to google how I convert that string
What else can the name be? I apparently don't understand what you mean by not knowing how to name it.
Just like that? Not the map before it?
With the map, I was just suggesting a simpler formula to use (100/(2850-1250) is 0.0625)
It doesnāt matter btw if itās field or mean, the error stays the same, itās expecting an float
You did not say there is an error, I thought it was working but with the wrong name against the line. What is the error?
I apparently don't understand what you mean by not knowing how to name it.
Well, somehow I have to address the value or the variable itās in. Thatās what I meant with that.
I was just suggesting a simpler formula to use
Ah, sorry I didnāt get that before.
What is the error?
error @5:58-5:66: expected float but found string
OK, I understand. Try
|> map(fn: (r) => ({ r with _value: 0.0625 * (2850.0 - r._value) })
That gives me a different error:
compilation failed: error @7:6-7:70: expected RPAREN, got EOF
Looks like you have lost a right parenthesis.
If you can't see it post the whole query here
Edit: there should be another one on the end.
Excellent
Der einfachste Weg ist vermutlich

