Help with a difference() in Grafana and Fllux for Influxdb 2

Hi I’m trying to create a Bar Gauge dashboard for my Energy consumption in Grafana

The data is composed of two values that needed to be summed to each other. This is done by the transformation.

The idea is to create a last seven days consumption by day. So there will be 7 bars one for each day. Looking a the data as a table I can see it has the total consumption since I start measuring it and adding to Influxdb 2. So, I need the difference between each day to get the daily usage.

This is the query I’m using

from(bucket: “Energy”)
|> range(start: -8d, stop: now())
|> filter(fn: (r) => r["_measurement"] == “quadro_geral”)
|> filter(fn: (r) => r["_field"] == “0_total” or r["_field"] == “1_total”)
|> aggregateWindow(every: 1d, fn: last, createEmpty: false)
|> difference( columns: [“Totalgeral}”], keepFirst: true)

It does not show the difference between each value. It shows the same total per day that I see without the difference function.

What am I doing wrong ?

welcome to the :grafana: forum, @andrelfsmartins

this sounds better suited for the bar chart rather than the bar guage. Have you tried that panel? You can see the needed data model in the docs:

Hi @mattabrams,

Thanks for the welcome and for the tip. It solved the problem of separating the values per day. Now I can see each day value as a bar.
The issue that remains is that it appears as the total power usage and not the daily usage. My idea was to use the difference() to accomplish it, but with or without it the values are the same, as if the function is not being applied.
I saw in another thread that difference() can only be applied to a table and there for I needed to use group(). The issue is that when I use group using _time, it generates a value for each minute and it’s totally meaningless.
How can I solve it ?