Result interpretation - Strange aggregate

I have following flux query:


import "date"
thisMonth = date.truncate(t: today(), unit: 1mo)

from(bucket: "home")
  |> range(start: thisMonth)
  |> filter(fn: (r) => r["_measurement"] == "vzlogger")
  |> filter(fn: (r) => r["Source"] == "S0_EG")
  |> filter(fn: (r) => r["_field"] == "Energy")
  |> aggregateWindow(every: 1d, fn: sum, createEmpty: false)

My intention is to get a daily sum across the current month, i.e. one daily total per day of the month.

Above is the screenshot from the InfluxDB UI.
Why am I getting two lines of results for 2021-12-21 (current day)? How to avoid this?

Many thanks for any input and a happy holiday season

@Monk aggregateWindow use the _stop column of each 1d window as the new _time value of the aggregate points. So where “today” is still in progress, you get a partial window and that _stop time of the window is essentially now(). One thing to also note is that because it’s using the _stop time of each window as the new _time, the value is actually that of the previous day.

To solve this, I’d recommend specifying the _start as the timeSrc in aggregateWindow():

import "date"
thisMonth = date.truncate(t: today(), unit: 1mo)

from(bucket: "home")
  |> range(start: thisMonth)
  |> filter(fn: (r) => r["_measurement"] == "vzlogger")
  |> filter(fn: (r) => r["Source"] == "S0_EG")
  |> filter(fn: (r) => r["_field"] == "Energy")
  |> aggregateWindow(every: 1d, fn: sum, timeSrc: "_start", createEmpty: false)
1 Like

@scott, many thanks, works like a charm. Still a lot to learn. Although I’m every time amazed by the power of InfluxDB, sometimes it feels like black magic. Thankfully there is such a supportive community.

@scott a related question if you allow:
If I understand correctly, this would apply to all aggregates > 1d?

@Monk Correct, it should.

1 Like