Query to return TRUE or FALSE based on simple conditional logic

Still learning Flux, so bear with me…

This is my query to display the Setpoint & Actual.

from(bucket: "bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "measurement")
  |> filter(fn: (r) => r["_field"] == "actualValue" or r["_field"] == "setpointValue")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")

image

The above is great, but what I would like to know now is if the absolute value of (setpointValue - actualValue) >= 7, and make it flexible by using a variable (instead of hard coding the ‘7’) defined at the start of the query.

For example (and this is totally wrong, but hopefully makes sense), to compare the absolute value of the difference between the Setpoint & Actual against a value of 7, how about something like this?

LIMIT = 7
if math.abs(setpointValue - actualValue) >= LIMIT then "true", else "false"

Once I work out syntax for the above conditional statement, do I just add the lines to my first query? Could it return “true” or “false” in a state timeline graph?

hallo,

limit = 6.85 // my battery voltage limit

join(tables: {d1: sensor_id, d2: ul_id}, on: [“BatUlId”]) //ignore these as i’m joining two tables
|> map(fn: (r) => ({
_time: r._time_d1,
_value: r._value_d1,
status: if r._value_d1 < limit then “low” else “high” //map with if/else
}))

then you will see new collumn: status with high/low info

pavel