Ternary operator in Influx flux

#1

I am doing a join in influx to get the first and last values for a interval and then getting the difference.

Preset = 600

FirstValues = from(bucket: "Historian/oneday")
  |> range(start: dashboardTime)
  |> filter(fn: (r) => 
    r._measurement == "TestMeasurement" and
    r._field =="Value"  and
    r.Loc=="TXS"
  )
 |>window(every:15m)
 |>first()


 LastValues = from(bucket: "Historian/oneday")
  |> range(start: dashboardTime)
  |> filter(fn: (r) => 
    r._measurement == "TestMeasurement" and
    r._field =="Value"  and
    r.Loc=="TXS"
  )
 |>window(every:15m)
 |>last()

 CombinedValues = join (
    tables:{first:FirstValues,last:LastValues},
    on:["_stop","_start"]
 )
 totaliser = CombinedValues
                |>map(fn: (r) => ({   
                    _time: r._start,
                    //Want to do this, r._value_first < r._value_last ? Preset : r._value_first
                    _value: r._value_first - r._value_last
                }))
 totaliser
 |>window(every:inf)

This works fine till the time difference returns a positive number.

But if the 1st value ,returned from join is less than 2nd value , I want to set perset value as first value (a>b).

Ex:

Preset = 600

totaliser = CombinedValues
                |>map(fn: (r) => ({   
                    _time: r._start,

                    //Want to do this, r._value_first < r._value_last ? Preset : r._value_first

                    _value: r._value_first - r._value_last
                }))
#2

Hi @suvvenndu ,

maybe you can use a combination of
math.m_max(x: r.x_value, y: r.y_value)
and
math.m_min(x: r.x_value, y: r.y_value)

and substract the min value from the max value ?

ore use

math.abs(x: r._value) ?

best regards ,

Marc