# If Else statement in flux query

**URL:** <https://community.influxdata.com/t/if-else-statement-in-flux-query/38830>\
**Category:** Systems\
**Created:** [October 19, 2024, 8:57am UTC](https://community.influxdata.com/t/if-else-statement-in-flux-query/38830 "2024-10-19T08:57:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AVVS\_Sudheer](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/avvs_sudheer/32/13075_2.png) [@AVVS\_Sudheer](https://community.influxdata.com/u/AVVS_Sudheer)\
**Post date:** [October 19, 2024, 8:57am UTC](https://community.influxdata.com/t/if-else-statement-in-flux-query/38830/1 "2024-10-19T08:57:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![thopewell](https://avatars.discourse-cdn.com/v4/letter/t/b782af/32.png) [@thopewell](https://community.influxdata.com/u/thopewell)\
**Post date:** [October 21, 2024, 8:31am UTC](https://community.influxdata.com/t/if-else-statement-in-flux-query/38830/2 "2024-10-21T08:31:41Z")

</div>

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:

```auto
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!
