Sum two measurement values

Good Morning!

I build my first bucket and the Grafana connect.
So far looks nice, but I was not able to sum two values:

from(bucket: "Database")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "PV")
  |> filter(fn: (r) => r["Wechselrichter"] == "1" or r["Wechselrichter"] == "2")
  |> filter(fn: (r) => r["_field"] == "Aktuelle Leistung")
  |> aggregateWindow(every: v.windowPeriod, fn: sum, createEmpty: false)
  |> yield(name: "sum")

I would like to sum this 2 values to get the total active power from both inverter.

Thank you!

Hi @hanhoe

I think this is easiest done using a Transformation in Grafana. See below.

Hi @grant1

Thank you … in the meantime I found this solution:

from(bucket: "Database")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "PV")
  |> filter(fn: (r) => r["Wechselrichter"] == "1" or r["Wechselrichter"] == "2")
  |> filter(fn: (r) => r["_field"] == "Aktuelle Leistung")
  |> group(columns: ["_time", "Aktuelle Leistung"])
  |> sum()
  |> group(columns: ["Aktuelle Leistung"])
  |> sort(columns: ["_time"])

You think this is ok or better your way?

1 Like

I do not think either is better than the other. Depends on your comfort level with Flux and Grafana’s options.

1 Like