How do I get the last value/measurement for each month for multiple sensors/entities/friendly_name?

I have a few sensors that reset the value every 1st day of the month. I have been using the last value with success but didn’t find a way to get the max/last value in a given calendar month. For each calendar month, for each sensor, I mean. I am a beginner working with flux.Preferably removing grouping it by month, and sensor (removing day, hour, and second after finding the max value for that month)

I tried the aggregate with one month, but it looks like it is not going to the last day of each month, and I wanted to have it for each month for each sensor.

This is my query, which returns the last value for each of the 20 sensors:

from(bucket: "home")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["friendly_name"] =~ /1MON$/ and r["friendly_name"] !~ /^Main/)
|> filter(fn: (r) => r["_field"] == "value")
|> filter(fn: (r) => r["_measurement"] == "kWh")
|> filter(fn: (r) => r["entity_id"] !~ /2$/)

Welcom @Roberto_Ferrari

Are you saying you tried the following and it did not go the last day of each month? It should.

|> aggregateWindow(every: 1mo, fn: last)
1 Like

thank you for your reply. I was aggregating and then sending it to last, this is much easier. I hadn’t tried this and feel so easy.

Glad it is working now. Can you please mark my post with “Solution” so others can find it in the future?

1 Like