Converting a negative value to poistive in Flux language

Hi@all,

I converted my InfluxDB from 1.xx to 2.61.
Also I upgraded from Grafana 7 to 9.3.2.
My Problem is a Panal where 2 values should be displayed.
One value is logged negative to influx.
So in my privious version I could add math and *-1 to correct that value.
But what do I have to do here with the flux language ??

the fronius.0.powerflow.P_Load value is negative and should be converted to positive…

from(bucket: “iobroker”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “fronius.0.powerflow.P_Load” or r[“_measurement”] == “fronius.0.powerflow.P_PV”)
|> filter(fn: (r) => r[“_field”] == “value”)
|> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)
|> yield(name: “last”)

Welcome

Check out map

thank you for the aswer.
unfortunatelly I don´t know how to insert this into my flux because of the two values…
Can you help me out ?

have you read the whole documentation of map posted above? and what have you tried and where is it failing?

@backons: Here is a hint. If you wanted to convert the values to degrees F, you could insert this line before the aggregateWindow function:

|> map(fn: (r) => ({r with _value: r._value * 1.8 + 32.0}))

when I insert this than an error:
invalid: runtime error: type conflict: int !=float
is occured

from(bucket: “iobroker”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “fronius.0.powerflow.P_Load” or r[“_measurement”] == “fronius.0.powerflow.P_PV”)
|> filter(fn: (r) => r[“_field”] == “value”)
|> map(fn: (r) => ({r with _value: r._value * -1 }))
|> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)
|> yield(name: “last”)

1 Like

Does changing it to -1.0 help, like this?

|> map(fn: (r) => ({r with _value: r._value * -1.0 }))

that works without error.
But it goes on both values and I have one negative and one positive.
So in this case negative one becomes positive and the postive one is now negative.
Only the value fronius.0.powerflow.P_Load should be turned from negative to positive.

Can you separate into two queries, i.e.

from(bucket: "iobroker")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "fronius.0.powerflow.P_PV")
|> filter(fn: (r) => r["_field"] == "value")
|> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)
|> yield(name: "PV")
from(bucket: "iobroker")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "fronius.0.powerflow.P_Load")
|> filter(fn: (r) => r["_field"] == "value")
|> map(fn: (r) => ({r with _value: r._value * -1.0 }))
|> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)
|> yield(name: "Load")