Multiplication of values

Hello!

I would like to multiplication and addition.

from(bucket: "Test")
  |> 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["String"] == "1" or r["String"] == "2")
  |> filter(fn: (r) => r["_field"] == "current" or r["_field"] == "voltage")

So I get 4 values:
Wechselrichter 1, String 1, current
Wechselrichter 1, String 1, voltage

Wechselrichter 1, String 2, current
Wechselrichter 1, String 2, voltage

Wechselrichter 2, String 1, current
Wechselrichter 2, String 1, voltage

Wechselrichter 2, String 2, current
Wechselrichter 2, String 2, voltage

At the end, I would like:
Power 1_1 = Wechselrichter 1, String 1, current * Wechselrichter 1, String 1, voltage
Power 1_2 = Wechselrichter 1, String 1, current * Wechselrichter 1, String 1, voltage
Power 2_1 = Wechselrichter 1, String 1, current * Wechselrichter 1, String 1, voltage
Power 2_2 = Wechselrichter 1, String 1, current * Wechselrichter 1, String 1, voltage

Sum = Power 1_1 + Power 1_2 + Power 2_1 + Power 2_2

I tried with pivot and map but not able to get a result.

Thank you!

hmmm … this seems correct?

from(bucket: "test")
  |> 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["String"] == "1" or r["String"] == "2" )
  |> filter(fn: (r) => r["_field"] == "current" or r["_field"] == "voltage")

  |> pivot(
       rowKey:["_time"],
       columnKey: ["_field"],
       valueColumn: "_value"
  )
  |> map(fn: (r) => ({r with _value: r.current * r.voltage}))

  |> group(columns: ["_time"])
  |> sum()
  |> group(columns: ["Power"])
  |> sort(columns: ["_time"])

Hello @hanhoe,
I’m glad you found a solution!
Thank you for sharing