If Else statement in flux query

Hi,

I have an if else statement in the below

|> filter(fn: (r) => r[“tag”]==“Profit” or r[“tag”]==“Loss”)
|> map(
fn: (r) => ({r with
level: if r.loss < 20 then
0
else
r.profit
}),
)

Here I am getting loss only, even if the value greater than 20. I must get only profit if the value is greater than 20

Hi @AVVS_Sudheer,

The example is a bit confusing, it seems you have a tag with literal name “tag” and values “Profit” and “Loss”, what are r.loss and r.profit, are those fields? i.e. if you were to write out the data you are ingesting in line protocol, would it be:

some_measurement,tag=Profit profit=100 1729498963
some_measurement,tag=Loss loss=19 1729498964

I’m thinking that r.loss and r.profit don’t appear in the same record and the map function only has one of them at a time. Could you provide a snapshot of what the raw data looks like?
Thanks!