# Cumulativesum of Aggregated data

**URL:** <https://community.influxdata.com/t/cumulativesum-of-aggregated-data/26938>\
**Category:** Dashboards\
**Tags:** flux\
**Created:** [October 11, 2022, 10:55pm UTC](https://community.influxdata.com/t/cumulativesum-of-aggregated-data/26938 "2022-10-11T22:55:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xk3tchuPx](https://avatars.discourse-cdn.com/v4/letter/x/13edae/32.png) [@xk3tchuPx](https://community.influxdata.com/u/xk3tchuPx)\
**Post date:** [October 11, 2022, 10:55pm UTC](https://community.influxdata.com/t/cumulativesum-of-aggregated-data/26938/1 "2022-10-11T22:55:08Z")

</div>

Hey,  
I’m trying to chart power consumption.  
Power usage is stored in Wh.

I can easily chart usage to view the raw data.

 ![Screen Shot 2022-10-11 at 5.39.41 PM](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/c/c27e06dad3568edabe6691e74a7d169bbb6bf750.png)

I’ve aggregated the data in 1h time frame so that I can see the usage per hour.

 ![Screen Shot 2022-10-11 at 5.42.50 PM](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/8/8aee05c2d96cdc144c830f59a619abc828be76e8.png)

```auto
from(bucket: "power")
  |> range(start: v.timeRangeStart, stop:v.timeRangeStop)
  |> filter(fn: (r) =>
    r._measurement == "Rack_1A" and
    r._field == "value"
  )
  |> aggregateWindow(every: 1h, fn: mean)

```

Now, what I want to do is to sum the hours (all the points in the previous chart) to have multiple subsequent chart (daily, weekly, monthly).

Anyone have an idea?

R,  
xk3tchupx

---

<div class="post-metadata">

**Author:** ![Jay\_Clifford](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jay_clifford/32/8287_2.png) [@Jay\_Clifford](https://community.influxdata.com/u/Jay_Clifford)\
**Post date:** [October 12, 2022, 9:46am UTC](https://community.influxdata.com/t/cumulativesum-of-aggregated-data/26938/2 "2022-10-12T09:46:35Z")

</div>

Hi @xk3tchuPx,  
So there are a few ways you could do this. The easiest way would be to use another aggregate window.

```auto
from(bucket: "power")
  |> range(start: -7d)
  |> filter(fn: (r) =>
    r._measurement == "Rack_1A" and
    r._field == "value"
  )
  |> aggregateWindow(every: 1h, fn: mean)
  |> aggregateWindow(every: 1d, fn: sum)

```

The above function sums all points within one day over a 7-day period. The second option is just to apply the sum() function though This would just total all points within your specified range.

```auto
from(bucket: "power")
  |> range(start: -7d)
  |> filter(fn: (r) =>
    r._measurement == "Rack_1A" and
    r._field == "value"
  )
  |> aggregateWindow(every: 1h, fn: mean)
  |> sum()

```

This would sum together all aggregated points
