Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
mplautz
Contributor III
Contributor III

Run set analysis *on* a variable

So, the internet is flooded with information on using variables inside of set analysis, but I'm more interested in know if there is a way to run set analysis *on* a variable. This is my use case:

I have a variable, vUSRevenue defined as such:

Sum({<CountryCode={'US'}, SalesStage={'4'}, QuarterSequence={'1','2','3','4','5','6','7','8','9'} >}Revenue)

When I want to use this variable as a measure, I can simply write a formula like:

$(vUSRevenue)

However, what if I want to add to the constraints within the set analysis? It seems like I could construct some syntax like:

$({<OtherConstraint={'Value'}>}vUSRevenue)

Except, that is not valid Qlik syntax. 

Is there a valid Qlik syntax that accomplishes what I'd like?

Labels (2)
3 Replies
Vegar
MVP
MVP

I haven't tried this my self, but you might be able to do it using parameters in your variable. 

Set vUSRevenue=Sum({< $1 CountryCode={'US'}, SalesStage={'4'}, QuarterSequence={'1','2','3','4','5','6','7','8','9'} >}Revenue

Then call it like this 

$(vUSRevenue(OtherConstraint={'Value'},))

You might get in trouble with the comma, if so then you could try to manipulate the parameter expression that it includes the comma as a part of the first parameter.

Please let us know if you succeed with this approach. 

Good luck.

Vegar

hendrik_faurie
Partner - Contributor II
Partner - Contributor II

Hi there,

 

This is just off the top of my head but I've done something similar before.

You can put the different pieces of Set Analysis into different variables, and then use them within your SUM.

Example:

v_Set_Revenue_Main (Do not use "=" sign in front here)

 CountryCode={'US'}, SalesStage={'4'}, QuarterSequence={'1','2','3','4','5','6','7','8','9'}

v_Set_Revenue_Add_1 (Do not use "=" sign in front here)

OtherConstraint={'Value'}

 

Then simply write your expression like: 

SUM({$1< $(v_Set_Revenue_Main ) , $(v_Set_Revenue_Add_1 ) >}Revenue)

Remember the comma between the 2 variables that would normally be there when you add additional constraints in Set Analysis, you could put the comma in v_Set_Revenue_Add_1  already as well like 

>>  ,OtherConstraint={'Value'}   << .

Edit: I guess you could go a step further as well and say.

SCRIPT:LET exp_Revenue = 'SUM({$1< $(v_Set_Revenue_Main ) , $(v_Set_Revenue_Add_1 ) >}Revenue)';

Variable Overview: SUM({$1< $(v_Set_Revenue_Main ) , $(v_Set_Revenue_Add_1 ) >}Revenue)

Expression: $(exp_Revenue)

 

Hope this helps or at least points you in the right direction.

 

Cheers

mplautz
Contributor III
Contributor III
Author

Of all the answers I see to this, this is the one that I like the most, as it seems to be the most intuitive for beginner and intermediate Qliksense users as far as extensibility goes. This is my business challenge though. I have beginner and intermediate users for Qlik, and the way my data is set up (as you can get a glimpse of above), I am trying to make building charts more intuitive for these users who are not as familiar with all of the different fields. However, by trying to make the app (and building charts) simpler, I've introduced a new problem by adding complexity when trying to do explicit filtering on measures (via set analysis). I feel like this will convey easily enough.