Flux: Monthly values of data that represents a total value

I have a zigbee plug that offers a data point of the total energy consumed, e.g. of my TV.

Example: At the beginning of the first month the value is 0 kw/h, at the end of the first month the value is 30 kw/h. At the beginning of the second month the value is 30 kw/h, at the end of the second month the value is 50 kw/h.

What I would like to display in Grafana is 30 kwh/h for the first month and 20 kw/h for the second month.

I am struggling in writing an approprate Flux query for this.

Can anybody point me in the right direction?

Hello @LordOfTheSnow,
I would use the following flux query:

from(bucket: "<yourbucket>"
|>range(start: <your start time>)
|> filter(fn: (r) => ...your filters)
|> aggregateWindow(every: 1mo, fn: last)