# Issue with aggregateWindow sum function

**URL:** <https://community.influxdata.com/t/issue-with-aggregatewindow-sum-function/19700>\
**Category:** InfluxDB 2\
**Tags:** influxdb, tasks\
**Created:** [May 2, 2021, 4:50pm UTC](https://community.influxdata.com/t/issue-with-aggregatewindow-sum-function/19700 "2021-05-02T16:50:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe\_Bastulli](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/joe_bastulli/32/7355_2.png) [@Joe\_Bastulli](https://community.influxdata.com/u/Joe_Bastulli)\
**Post date:** [May 2, 2021, 4:50pm UTC](https://community.influxdata.com/t/issue-with-aggregatewindow-sum-function/19700/1 "2021-05-02T16:50:20Z")

</div>

Hello,

I am aggregating tick data and I seem to not understand why I am having issues with summing the volume field. It will not write data until I change **fn: sum** to **fn: last** , however I want to sum the data for this field. Below I attached some sample code with the sum aggregation that does not work as well as the another aggregation for the opening tick data which works just fine. What am I doing wrong?

```
parameters = {
	start: -3m,
	every: 1m,
	limit: 3,
	bucket: "CryptoData",
	org: "test",
}
dataset = from(bucket: parameters.bucket)
	|> range(start: parameters.start)
	|> filter(fn: (r) =>
		(r["_measurement"] == "CoinbasePro"))
	|> filter(fn: (r) =>
		(r["_field"] == "volume" or r["_field"] == "price"))

dataset
	|> filter(fn: (r) =>
		(r["_field"] == "volume"))
	|> aggregateWindow(every: parameters.every, fn: sum)
	|> map(fn: (r) =>
		({
			_time: r._time,
			product_id: r.product_id,
			_field: "volume",
			_measurement: r._measurement,
			_value: r._value,
			topic: r.topic,
			symbol: r.symbol,
		}))
	|> limit(n: parameters.limit)
	|> to(bucket: "ohlc_1m_data", org: "none")
dataset
	|> filter(fn: (r) =>
		(r["_field"] == "price"))
	|> aggregateWindow(every: parameters.every, fn: first)
	|> map(fn: (r) =>
		({
			_time: r._time,
			product_id: r.product_id,
			_field: "open",
			_measurement: r._measurement,
			_value: r._value,
			topic: r.topic,
			symbol: r.symbol,
		}))
	|> limit(n: parameters.limit)
	|> to(bucket: "ohlc_1m_data", org: "none")
```

---

<div class="post-metadata">

**Author:** ![Joe\_Bastulli](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/joe_bastulli/32/7355_2.png) [@Joe\_Bastulli](https://community.influxdata.com/u/Joe_Bastulli)\
**Post date:** [May 2, 2021, 9:46pm UTC](https://community.influxdata.com/t/issue-with-aggregatewindow-sum-function/19700/2 "2021-05-02T21:46:46Z")

</div>

I believe I solved the issue by calling the

```auto
|> cumulativeSum()

```

function after the aggregation. It seems to be working now
