Hi!
I just installed my first Grafana instance along with an influx 2 database. There is obviously a lot to learn. I am sort of familiar with sql queries, the flux language is something I have to get used to first…
So maybe someone can help me with my first “problem”
My goal is to display the produced energy in kwh for the currently selected time range of my dashboard.
The data source is a growing number in kwh
I managed to achieve something static for one day with this query (I have no idea what I am doing here, so please bare with me).
from(bucket: "iobroker")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "sourceanalytix.0.shelly__1__shellyplus1pm#7c87ce64d6d0#1__Relay0__Energy.cumulativeReading")
|> filter(fn: (r) => r["_field"] == "value")
|> aggregateWindow(every: 1d, fn:last)
|> difference()
|> yield(name: "mean")
The output of this is exactly what I need. But as soon as I am switching the dashboard from “Last 24 hours” to something smaller it just displays “No Data” which makes sense…
How can I adjust my query to dynamically calculate the difference between the first and the last value of the currently selected time range?