Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
dandaanilreddy
Partner - Creator III
Partner - Creator III

Multiple If conditions in qlik sense script

Hello All,

I have used multiple if conditions and created a new field in script but only my first condition is working. I know this is because my first condition is coming as true and it is not going to next conditions. Is there a way i can achieve this in script?

if(match(product,'Test1','Test2'),'Cal_1,

if(product='Test3' and category='Loss','Calc_2',

if(category='Loss','Calc_3'

))) as new_field

The above is an example i have total 16 if conditions.

3 Replies
mato32188
Specialist
Specialist

Hi @dandaanilreddy ,

I would suggest you to split logic of above into flags. It can make it much more easier to read and better to identify any mistake in complex statement logic.

Split can look like this:

Load

if(match(product,'Test1','Test2'), 1, 0) as Is_Calc1,

if(product='Test3' and category='Loss',1,0) as Is_Calc2,

if(category='Loss',,1,0) as Is_Calc3

FROM xxx;

Then you can create three expressions using set analysis

sum({<Is_Calc1 = {1}>} xxx), sum({<Is_Calc2 = {1}>} xxx), sum({<Is_Calc3 = {1}>} xxx) or you can combine them in a way you want, like

sum({<Is_Calc1 = {1}, Is_Calc2 = {1}>} xxx), sum({<Is_Calc2 = {1}, Is_Calc3 = {1}>} xxx)

This is the way I prefer.

BR

m

 

ECG line chart is the most important visualization in your life.
AnalyticsBoost
Contributor III
Contributor III

if(match(product,'Test1','Test2') and category='Loss','Cal_1,

if(match(product,'Test3') and category='Loss', 'Calc_2',

if(match(product,'Test1','Test2','Test3') and category='Loss','Calc_3'

))) as new_field

mato32188
Specialist
Specialist

I do not quite understand what you want to achieve. Match function works as OR, so if category is Loss and product is either Test1 or Test2, returns Cal_1. If this is not true, second if statement is going to be evaluated, means if category is loss and product is Test3 returns Calc_2.  Once you have only 3 products (Test1,Test2,Test3), the last if statement that should return Calc_3 will be true only if category is other than Loss.

Could you please write in sentences your desired output? It might help to better understand concept.

Thank you.

br

m

 

ECG line chart is the most important visualization in your life.