Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
snowman
Contributor III
Contributor III

IF OR syntax in expression with variable

Hi,

I am not sure the right syntax for using OR within the IF function with variable:

For example, I have a variable, vFood, which could be: 'apple', 'orange', 'beef', 'chicken', ….

Now I want to define a new variable, vFood_type, which will show 'fruit',  'meat', 'other'

IF('$(vFood)'='apple' OR 'orange', 'fruit', IF('$(vFood)'='beef' OR 'chicken', 'other'))

The result was that only the first parameter was evaluated, and when vFood = 'orange' or 'chicken', it gives 'other'.

Any advice ?  I can use multiple IF function to replace OR, but it would take me 10+ IF  loops in my real case

Thanks.

 

 

1 Solution

Accepted Solutions
Saravanan_Desingh

Try this.

=Pick(Match($(vFood),'apple', 'orange', 'beef', 'chicken')+1,'other','fruit','fruit','meat','meat')

apple = fruit

beef = meat

milk = other

View solution in original post

5 Replies
Saravanan_Desingh

Try this.

=Pick(Match($(vFood),'apple', 'orange', 'beef', 'chicken')+1,'other','fruit','fruit','meat','meat')

apple = fruit

beef = meat

milk = other

snowman
Contributor III
Contributor III
Author

Hi @Saravanan_Desingh 

Thanks a lot for your prompt advice and especially on Sunday. May I also know the usage of +1 in your example ?

 

Saravanan_Desingh

By +1, I push OTHERWISE to the first place ('other'). For 'milk' the value will be 'other'.

snowman
Contributor III
Contributor III
Author

Great! You are very helpful.

Thanks a lot.

Saravanan_Desingh

you welcome