InfluxDB 2.0 | Query Data and aggregate multiple times

919 Views Asked by At

I have a photovolatic system and log the generated electricity in KwH at each change in an InfluxDB 2.0.

Now I want to have a graph of the monthly yields in Grafana. For this I need to load the last value of the day and sum it up per month. Actually a simple query, but unfortunately I can't get it implemented.

The following query I tried and expected it to work:

from(bucket: "Home Assistant")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "sensor.kaco_29")
  |> filter(fn: (r) => r["_field"] == "kwh_today")
  |> aggregateWindow(every: 1d, fn: last)
  |> aggregateWindow(every: 1m, fn: sum)

Loading the last daily value works, without the last line without any problems. How do I get the data summed up per month?

1

There are 1 best solutions below

0
On

Did you try grouping after the first aggregation?

Add

|> group()

between the two aggregateWindow() functions.