Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
ashis
Creator III
Creator III

How to pass if condition in set analysis expression

Hello,

I am trying to pass if condition inside a set analysis expression. Below is my expression that is not working.

In the below example  I used 0=0 and 1=1 for variable place holder. 

sum({<if(0=0, countryflag={1}, countryflag={2}),
if(1=1, userflag={1},'')>}sales)

 

it is giving error in set modifier expression. Please help.

Labels (3)
2 Solutions

Accepted Solutions
vinieme12
Champion III
Champion III

should be represented as string in single quotes

var1=if(0=0, 'countryflag={1}, countryflag={2}');

var2=if(1=1, 'userflag={1}','');

 

then 

count({<$(=var1),$(=var2)>} sales)

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.

View solution in original post

ashis
Creator III
Creator III
Author

Hi  Vineeth,

Thank you for your reply .  Actually this works

var1=if(0=0, 'countryflag={1}', 'countryflag={2}');

 

 

View solution in original post

7 Replies
vinieme12
Champion III
Champion III

If you want to have a different expression based on dimension value then place your expression inside an if() block 

=If(Dim=1, 

sum({<countryflag={1}, countryflag={2}>}sales)

,If(Dim=0,sum({<Userflag={1}>}sales)))

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
ashis
Creator III
Creator III
Author

Hi Vineeth,

Thank you for your reply. I want to place if condition inside set analysis syntax, reason being I want to pass variable in side it.

For example, 

var1=if(0=0, countryflag={1}, countryflag={2});

var2=if(1=1, userflag={1},'');

Finally it would go inside set expression

count({<$(var1),$(var2)>} sales)

vinieme12
Champion III
Champion III

should be represented as string in single quotes

var1=if(0=0, 'countryflag={1}, countryflag={2}');

var2=if(1=1, 'userflag={1}','');

 

then 

count({<$(=var1),$(=var2)>} sales)

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
ashis
Creator III
Creator III
Author

Hi  Vineeth,

Thank you for your reply .  Actually this works

var1=if(0=0, 'countryflag={1}', 'countryflag={2}');

 

 

vinieme12
Champion III
Champion III

yes, because it needs to be expressed as a string which would then be evaluated during the $() expansion

I assumed this was one string   'countryflag={1}, countryflag={2}'

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
ashis
Creator III
Creator III
Author

Thank you for your reply. 😁 

vinieme12
Champion III
Champion III

kindly close the thread by marking a response as solution

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.