Hello
I have created a Bucket with different measurement values in it. Below is an example Query from reading. I would like to display the difference of two values.
Get the value “HALA2” - “HALA1”
from(bucket: “DUR”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “modbus”)
|> filter(fn: (r) => r[“_field”] == “Energy”)
|> filter(fn: (r) => r[“host”] == “INFlux”)
|> filter(fn: (r) => r[“name”] == “HALA2” or r[“name”] == “HALA1”)
|> filter(fn: (r) => r[“slave_id”] == “1”)
Hi @fantastiko, welcome to the community!
You can use pivot and map to achieve this:
from(bucket: “DUR”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “modbus”)
|> filter(fn: (r) => r[“_field”] == “Energy”)
|> filter(fn: (r) => r[“host”] == “INFlux”)
|> filter(fn: (r) => r[“name”] == “HALA2” or r[“name”] == “HALA1”)
|> filter(fn: (r) => r[“slave_id”] == “1”)
|> pivot(rowKey: ["_time"], columnKey: ["name"], valueColumn: "_value")
|> map(fn: (r) => ({r with _value: r.HALA2 - r.HALA1}))