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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
krc123
Contributor
Contributor

Nested If Statements, many conditions

I am looking for a way to code many different conditions into if statements. The source data is all different and I am trying to generate a new column. There are 16 clients. So far I have:

IF '$(vClientCode)' = 'XXX' THEN
If([compound code]=2,'Compound')
If([drug type]=4 and [Generic Indicator]=Y,'Generic')
If([drug type]=1 or [drug type]=2 or [drug type]=4 or [drug type]=5,'Brand')
Else 'Generic';

IF '$(vClientCode)' = 'XXX' THEN
If([compound indicator]=2,'Compound')
If([SSG Ind]=SSG,'Single-Source Generic')
If([Drug Indicator]<>Y,'Brand')
Else 'Multi-Source Generic';

Labels (4)
1 Solution

Accepted Solutions
Bunim
Contributor III
Contributor III

IF ('$(vClientCode)' = 'XXX' ,
If([compound code]=2,'Compound',
If([drug type]=4 and [Generic Indicator]=Y,'Generic',
If([drug type]=1 or [drug type]=2 or [drug type]=4 or [drug type]=5,'Brand',
'Generic'))) ,
IF ('$(vClientCode)' = 'XXX' ,
If([compound indicator]=2,'Compound',
If([SSG Ind]=SSG,'Single-Source Generic',
If([Drug Indicator]<>Y,'Brand',
'Multi-Source Generic'))))) AS "new column"

View solution in original post

2 Replies
Bunim
Contributor III
Contributor III

IF ('$(vClientCode)' = 'XXX' ,
If([compound code]=2,'Compound',
If([drug type]=4 and [Generic Indicator]=Y,'Generic',
If([drug type]=1 or [drug type]=2 or [drug type]=4 or [drug type]=5,'Brand',
'Generic'))) ,
IF ('$(vClientCode)' = 'XXX' ,
If([compound indicator]=2,'Compound',
If([SSG Ind]=SSG,'Single-Source Generic',
If([Drug Indicator]<>Y,'Brand',
'Multi-Source Generic'))))) AS "new column"

krc123
Contributor
Contributor
Author

Thank you! I am not able to test this fully yet because other pieces are not built out, but the editor is not turning any of my code red, so I think it's all good.