Flux: aggregating with a monthly window shows the wrong month

I aggregate temperature values by monthly windows like this:

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?

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

1 Like

Further to what @MzazM wrote, here is a more comprehensive explanation of the various function parameters: aggregateWindow() function | Flux 0.x Documentation

1 Like

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

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

does the trick.

1 Like