Cumulative sum influxdb data

Not sure, whether I’m in the right forum here. So please advise, if this is not the case. I’m using Home Assistant data from influxdb to display grafana charts. Basically, I would like to transform the first graph into the second graph.

The source sensor gets reset to zero occasionally (reboot of the counter device or …) while I would like to continue to graph from its previous level.



I hope that the problem description is not too confusing.


Forgot to add that the original graph was created with SELECT "value" FROM "m³" WHERE ("entity_id" = 'gasverbrauch') AND $timeFilter

Ok, after some more googling, I’ve solved it myself. For the record Aggregate function required inside the call to cumulative_sum - Dashboards - InfluxData Community Forums helped me come up with

SELECT CUMULATIVE_SUM(SUM(nnd)) FROM ( SELECT NON_NEGATIVE_DIFFERENCE("value") AS nnd FROM "m³" WHERE ("entity_id" = 'gasverbrauch') AND $timeFilter ) GROUP BY time(1d)