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

Announcements
Posting on Qlik Community is temporarily paused. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
pala_jagadeesh
Contributor III
Contributor III

multiple IF condition

Hi 

How to write multiple if condition here for

 if s1=a and s2=e   condition=yes

   s1=b and s2=f    condition=yes 

  s1=c and s2=g   condition=yes

   s1=d and s2=h  condition= yes

for remaining all condition=n0

 

ID S1 S2
1 a e
2 b f
3 c g
4 d h
5 d k
6 d l

 

output

ID condition
1 yes
2 yes
3 yes
4 yes
5 No
6 No
Labels (4)
2 Replies
brunobertels
Master
Master

Hi 

Try this as mesure 

if(S1='a' and S2 ='e'
or S1='b' and S2='f'
or S1='c' and S2='g'
or S1='d' and S2='h',
'YES','NO')

Or in the script : 

condition:
load * ,
if(S1='a' and S2 ='e'
or S1='b' and S2='f'
or S1='c' and S2='g'
or S1='d' and S2='h',
'YES','NO') as Condition;


load *inline [
ID, S1, S2
1, a, e
2, b, f
3, c, g
4, d, h
5, d, k
6, d, l
](delimiter is ',');

 

brunobertels_1-1660746021990.png

 

 

marcus_sommer
MVP
MVP

With a slight tweak by wrapping the OR statements with brackets you may apply the suggestion from @brunobertels. Another possibility might be to query both fields together, for example like:

if(match(s1 & '|' s2, 'a|e', 'b|f', ...), 'yes', 'no')

By a larger number of combinations it might be more suitable to load them within a mapping table and querying the results from there.

- Marcus