# Flux: aggregating with a monthly window shows the wrong month

**URL:** <https://community.influxdata.com/t/flux-aggregating-with-a-monthly-window-shows-the-wrong-month/29208>\
**Category:** Fluxlang\
**Tags:** time-series, flux\
**Created:** [March 23, 2023, 7:16pm UTC](https://community.influxdata.com/t/flux-aggregating-with-a-monthly-window-shows-the-wrong-month/29208 "2023-03-23T19:16:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![LordOfTheSnow](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/lordofthesnow/32/10705_2.png) [@LordOfTheSnow](https://community.influxdata.com/u/LordOfTheSnow)\
**Post date:** [March 23, 2023, 7:16pm UTC](https://community.influxdata.com/t/flux-aggregating-with-a-monthly-window-shows-the-wrong-month/29208/1 "2023-03-23T19:16:21Z")

</div>

I aggregate temperature values by monthly windows like this:

```auto
import "date"

dataSet = from(bucket: "rtl_433")
    |> range(start: -1y, stop: date.truncate(t: now(), unit: 1mo))
// |> range(start: 2022-07-01T00:00:00Z, stop: 2022-07-31T00:00:00Z) 
    |> filter(fn: (r) => r._measurement == "Nexus-T")
    |> filter(fn: (r) => r._field == "temperature_C")
    |> filter(fn: (r) => r.channel == "2")

dataSet
    |> aggregateWindow(every: 1mo, fn: mean, createEmpty: false)

```

The resulting data is always shifted by one month, e.g. values cumulated for July 22 are displayed as “08/01” (1st of August).

I would like to have them shown as “07/01”.

Does anybody know how to achieve this?

---

<div class="post-metadata">

**Author:** ![MzazM](https://avatars.discourse-cdn.com/v4/letter/m/fbc32d/32.png) [@MzazM](https://community.influxdata.com/u/MzazM)\
**Post date:** [March 24, 2023, 6:16am UTC](https://community.influxdata.com/t/flux-aggregating-with-a-monthly-window-shows-the-wrong-month/29208/2 "2023-03-24T06:16:55Z")

</div>

There are additional options when calling the aggregate window function. By default the dstsrc (or something similar) is set as tstop of your range. You want to change that to tstart

---

<div class="post-metadata">

**Author:** ![grant1](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/grant1/32/15107_2.png) [@grant1](https://community.influxdata.com/u/grant1)\
**Post date:** [March 24, 2023, 11:35am UTC](https://community.influxdata.com/t/flux-aggregating-with-a-monthly-window-shows-the-wrong-month/29208/3 "2023-03-24T11:35:37Z")

</div>

Further to what @MzazM wrote, here is a more comprehensive explanation of the various function parameters: [aggregateWindow() function | Flux 0.x Documentation](https://docs.influxdata.com/flux/v0.x/stdlib/universe/aggregatewindow/)

---

<div class="post-metadata">

**Author:** ![LordOfTheSnow](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/lordofthesnow/32/10705_2.png) [@LordOfTheSnow](https://community.influxdata.com/u/LordOfTheSnow)\
**Post date:** [March 24, 2023, 7:16pm UTC](https://community.influxdata.com/t/flux-aggregating-with-a-monthly-window-shows-the-wrong-month/29208/4 "2023-03-24T19:16:05Z")

</div>

Once again, thanks a lot for pointing me in the right direction.

` |> aggregateWindow(every: 1mo, fn: mean, createEmpty: false, timeSrc: "_start")`

does the trick.
