# Cumulative sum influxdb data

**URL:** <https://community.grafana.com/t/cumulative-sum-influxdb-data/57642>\
**Category:** InfluxDB\
**Created:** [December 13, 2021, 8:31pm UTC](https://community.grafana.com/t/cumulative-sum-influxdb-data/57642 "2021-12-13T20:31:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefanwaldherr](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@stefanwaldherr](https://community.grafana.com/u/stefanwaldherr)\
**Post date:** [December 13, 2021, 8:31pm UTC](https://community.grafana.com/t/cumulative-sum-influxdb-data/57642/1 "2021-12-13T20:31:48Z")

</div>

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.

Before

 ![before](https://us1.discourse-cdn.com/grafana/original/3X/6/7/67bee882b94a9f13988042872f6b5971e1c65ba8.png)

After

 ![after](https://us1.discourse-cdn.com/grafana/original/3X/f/3/f3e035ea4cd312b01608ff9ba78146d907296bd1.png)

I hope that the problem description is not too confusing.

Stefan

---

<div class="post-metadata">

**Author:** ![stefanwaldherr](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@stefanwaldherr](https://community.grafana.com/u/stefanwaldherr)\
**Post date:** [December 13, 2021, 8:48pm UTC](https://community.grafana.com/t/cumulative-sum-influxdb-data/57642/2 "2021-12-13T20:48:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stefanwaldherr](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@stefanwaldherr](https://community.grafana.com/u/stefanwaldherr)\
**Post date:** [December 13, 2021, 9:03pm UTC](https://community.grafana.com/t/cumulative-sum-influxdb-data/57642/3 "2021-12-13T21:03:42Z")

</div>

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](https://community.influxdata.com/t/aggregate-function-required-inside-the-call-to-cumulative-sum/12594) 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)`
