If else statement in InfluxDB

Hi,

I am using the if else statement as below in my query

|> map(
fn: (r) => ({r with
level: if r._value >= 0 and r._value <= 1 then
“Profit”
else
“Loss”,
}),
)

My question is I think it is not working correctly as it is showing profit when the value is 20 for one of the date. Actually it must show loss. Is this right or wrong.

Hello @AVVS_Sudheer,
Hmm that’s very odd.
Can you share the full query and the erroneous output?
I’ve never experienced that type of error before.
What version are you using? Can you upgrade maybe?

Hi Anais,

My query is below

|> map(
fn: (r) => ({r with
level: if r._value >= 0 and r._value <= 1 then
“Profit”
else
“Loss”,
}),
)

It must return loss if the value is > (greater than) 1. In my output data for some dates the values are greater than 1, then it must show loss.

I tried the below query also which is just modified the above one

|> map(
fn: (r) => ({r with
level: if r._value >= 0 and r._value < 1 then
“Profit”
else
“Loss”,
}),
)

It is working fine if I have only 3 or 4 rows of data.