aggregateWindow(every: 1mo, fn: first) ... not reporting very first value in a time series

Hi,

I have a time series of incrementing energy measurements like so:

2021-02-08 09:20:25 89503600
2021-02-08 09:21:25 89503600 
2021-02-08 09:23:11 89503600
2021-02-08 09:24:10 89503600
2021-02-08 09:25:09 89503600
2021-02-08 09:26:09 89503600
2021-02-08 09:27:13 89503600
2021-02-08 09:46:13 89504000
2021-02-08 09:47:11 89504100
2021-02-08 09:48:10 89504100
....
....
2021-03-19 09:28:10 89702300
2021-03-19 09:29:10 89702300
2021-03-19 09:30:11 89702400
2021-03-19 09:31:10 89702700

The values are in kWh. In order to determine the enery consumption in a time window, it would just take the last value in a time window minus the first value in a time window – or alternatively: Split the range into multiple time windows and take the difference between the first values like so:

from(bucket: "powerrouter")
  |> range(start: v.timeRangeStart, stop:v.timeRangeStop)
  |> filter(fn: (r) => r._measurement == "E_GRID_TOTAL" and r._field == "value" )
  |> aggregateWindow(every: 1d, fn: first, createEmpty: false)
  |> difference()

Now this works and I get the energy consumption for each day.

What I want, however, is the energy consumption in every month. I have data starting from 8.2.2021 until today 19.3. So I’ve changed the above to read:

  from(bucket: "powerrouter")
      |> range(start: v.timeRangeStart, stop:v.timeRangeStop)
      |> filter(fn: (r) => r._measurement == "E_GRID_TOTAL" and r._field == "value" )
      |> aggregateWindow(every: 1mo, fn: first, createEmpty: false)
      |> difference()

And the strange thing is, that I only get data for March and not for February.

2021-03-19 13:12:24 1192000

When I remove the difference() function, I get two values:

2021-03-01 01:00:00  89503600
2021-03-19 13:13:20  90695600

But where is the very first value from 8.2.2021:

2021-02-08 09:20:25 89503600

Why is it not included in the agregateWindow output?

Thanks // Tom

How about use aggretate.rate rather than aggregateWindow