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

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
chriys1337
Creator III
Creator III

Logical Operators And OR - operating mode

Hi,

I am working on an if condition and questioning how it is working:

if(x=1 and y=0 or y= null(),'yes','no') as test

 

is it (1st condition must be valid AND 2nd  condition must be valid) OR 3rd condition must be valid (only)

vs

1st condition must be valid AND (2nd condition must be valid OR 3rd condition must be valid) ?

If it is working like described in the second mode, I would need to rewrite my if statement to

 

if(x=1 and y=0 or x=1 and y= null(),'yes','no') as test2

Thanks for sharing your insights.

Labels (1)
1 Reply
Vegar
MVP
MVP

When more than one logical operator is used in a condition, NOT is evaluated first, then AND, and finally OR. The best way to straighten this so there no confusion is to group the logical bulks with parentheses. 

 

if(x=1 and (y=0 or y= null() ),'yes','no') as test

 

In your case I would also recommend to switch the y=null() with isnull(y) like this 

if(x=1 and( y=0 or isnull(y)) ,'yes','no') as test