A table can contain both positive and negative values. Now I don’t want to hide the negative values but replace them with 0 values. I tried that with the following code. The negative values are also recognized and replaced with 0. However, the positive values should be retained. I haven’t managed to do that yet. Where is the error in my code?
from(bucket: "telegraf")
|> range(start: today())
|> filter(fn: (r) => r["_field"] == "Total DC power (sum of all PV inputs)")
|> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)
|> map(
fn: (r) => ({r with
level: if r._value <= 0.0 then
"0.0"
else
"r._value",
}),
)
Also, the value in the new column should be a number.