Difference function with cumulative series falling to zero

I have this Flux query to draw a month bargraph :

from(bucket: “homeassistant/autogen”)
|> range(start: 2022-12-31T23:50:00Z, stop: 2023-12-31T23:59:59Z)
|> filter(fn: (r) => r._measurement == “kWh” and r._field == “value”)
|> filter(fn: (r) => r.entity_id == “cumulus_ch_parents_energy”)
|> aggregateWindow(every: 1mo, fn: last, createEmpty: true)
|> difference(nonNegative: true)
|> timeShift(duration: -1mo)

till july, all is fine : the bargraph is good.
but in august, the cumulative serie have been reset to zero and no bargraph is displayed
i’ve try to mix all values with nonNegative and initialZero : no success

i’ve an other query (not in Flux)a for weekly bargraph : the falling to zero is not a problem, the bargraph is displayed.

so, what can i do in my Flux to fix ?

the values of the serie :

thanks.

Welcome @alainvdu69

I believe you’ll need to use the increase() function in Flux.

This post might help you get started.

1 Like

Nice.
I’ve juste added increase() before the aggregateWindow.