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

Announcements
Independent validation for trusted, AI-ready data integration. See why IDC named Qlik a Leader: Read the Excerpt!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Set analysis question

hi , how can i convert this ‘if’ statement into ‘Set Analysis’:      (sum({$<segfuerza={'P1'}>}visitc))


sum(visitc)/ if(Pais= 'BH',
 
if(TIPO_Cliente = 'PRES',
 
if(Fuerza <>'SP',124,
  
if(Fuerza='SP',95,
  
if(Region='WI',
  
if(TIPO_Cliente='PRES',SUM(Vp))))),sum(Vp)),
  
if(Pais= 'BB',
 
if(TIPO_Cliente = 'PRES',
 
if(Fuerza <>'SP',124,
  
if(Fuerza='SP',95,
  
if(Region='WI',
  
if(TIPO_Cliente='PRES',SUM(Vp))))),sum(Vp)),
  
if(Pais= 'AC',
 
if(TIPO_Cliente = 'PRES',
 
if(Fuerza <>'SP',114,
  
if(Fuerza='SP',95,
  
if(Region='WI',
  
if(TIPO_Cliente='PRES',SUM(Vp))))),sum(Vp)),
  
if(Pais= 'JA',
 
if(TIPO_Cliente = 'PRES',
 
if(Fuerza <>'SP',152,
  
if(Fuerza='SP',133,
 
if(Region='WI',
  
if(TIPO_Cliente='PRES',SUM(Vp))))),sum(Vp)),
  
if(Pais= 'TT',
 
if(TIPO_Cliente = 'PRES',
 
if(Fuerza <>'SP',152,
  
if(Fuerza='SP',133,
  
if(Region='WI',
  
if(TIPO_Cliente='PRES',SUM(Vp))))),sum(Vp)), 
  
  
sum(Vp)))))) 


4 Replies
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

That expression cannot be changed into a set analysis expression. Your expression doesn't just filter values, but contains a lot of branches that each return a different result. That kind of logic can't be done with set analysis. Also an if(...some_condition...,sum(...some_thing...)) is not necessarily the same as a sum(if(...some_condition...,...something...)).


talk is cheap, supply exceeds demand
Not applicable
Author

whats the difference?

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

For example, with if(sum(A)>B,sum(A)) you first calculate the sum of values and then do a comparison of the sum with something, with sum(if(A>B,A)) you first do a comparison of the values before they are summed and only then do a sum.


talk is cheap, supply exceeds demand
Not applicable
Author

Gysbert Wassenaar is right, your expression contains lots of branches.

But you can surely reduce these branches by taking out the common parts and then using set analysis.

I figured out that : sum({<TIPO_Cliente = {"PRES"},Region = {"WI"}>}Vp)

this is common to all branches. So you can surely improve your expression.

Thanks,

Angad