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

Announcements
Now accepting applications for the Qlik Luminary and Partner Ambassador Programs: Apply by July 6!
cancel
Showing results for 
Search instead for 
Did you mean: 
PabloMC
Contributor III
Contributor III

if condition inside Set analysis

Hi, 

I have a table with values like the following (simplified example):

 
Country    ProductId    Sales
Spain      1            100
France     1            100
England    1            100
Portugal   1            100
Spain      2            50
France     2            50
England    2            50
Portugal   2            50

What I need is a Set Analysis expression where:

  • For France, only ProductId = 1 should be included

  • For all other countries, all ProductId values should be included

I know I can do something like:

 
If(Country = 'France', Sum({<ProductId={1}>} Sales), Sum(Sales))

…but I do not want to use an if() outside the Set Analysis. I want the logic to be fully inside the Set modifier.

Something like this (which I know does not work):

 
Sum({<ProductId = {if(Country='France', 1, '*')}>} Sales)

Is it possible to pass this conditional logic directly into the Set Analysis?

My goal is to avoid row‑level if() and keep everything inside the set.

 

Thanks

Labels (3)
4 Replies
Or
MVP
MVP

It seems like it would be much easier to just use two sums - one for France and one for everything else - and add those?

That said, the set analysis shouldn't be a problem using the union (+) operator and excluding France from one half:

{$<country -= {'France'}> + <country = {'France'}, ProductId = {1}>}

Lech_Miszkiewicz
Partner Ambassador/MVP
Partner Ambassador/MVP

How about below?

 

Sum({<Country={'France'},ProductId = {1}>+<Country-={'France'}>} Sales)

  

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.
PabloMC
Contributor III
Contributor III
Author

The problem is that not always have to do that with France.

If user select all countries, don't have to include only ID 1, but if user select some countries, and if in this list of countries is France selected, it have to include only ID 1. 

I think i have to do an IF statement inside set analysis

thanks

 

Lech_Miszkiewicz
Partner Ambassador/MVP
Partner Ambassador/MVP

Sorry @PabloMC 

Your statement is not fully correct or it does not match the formula you would use with statement you wanted to do:

If(Country = 'France', Sum({<ProductId={1}>} Sales), Sum(Sales))

 

If the rule is that if France is withing possible values then for France use ProductID=1 and for all other countries use all possible products then what we suggested was "almost" correct. 

I would adjust this by adding * (intersection) sign for France so that it applies only when France is within possible values, like so:

Sum({<Country*={'France'},ProductId = {1}>+<Country-={'France'}>} Sales)

 

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.