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 in Expression/Variable

Hello All,

Could someone can explain me why this set analysis works in expression and doesn't work when I put it into a variable ?

My Script :

set test = chr(39)&'<'&max(Year)*10000&chr(39);

set SalesYear=Sum({$ <[Date]={$(=$(test))}>} [Sales]);

In my chart when I use directly my expression of "SalesYear" it works fine, but when I use the variable "SalesYear" I've only 0 values.

Qlik_SalesYear.png

When I put my variable in text object It displays this :

=Sum({$ <[Date]={}>} [Sales])

I don't understand what happen in my variable.

Have a good day,

1 Solution

Accepted Solutions
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

set SalesYear=Sum({$ <[Date]={$(=$(test))}>} [Sales]);

$(test) will be dollar-expanded in the script. Since test is not defined the result is nothing. And then $( ...nothing... ) is expanded too so the result is that SalesYear will have the value Sum({$ <[Date]={}>} [Sales]).

What you can do instead is this:

set SalesYear=Sum({$ <[Date]={@(=@(test))}>} [Sales]);

let SalesYear=replace('$(SalesYear)','@','$');


Or this:


LET SalesYear = 'Sum({$ <[Date]={$' & '(=$' & '(test))}>} [Sales])';


talk is cheap, supply exceeds demand

View solution in original post

2 Replies
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

set SalesYear=Sum({$ <[Date]={$(=$(test))}>} [Sales]);

$(test) will be dollar-expanded in the script. Since test is not defined the result is nothing. And then $( ...nothing... ) is expanded too so the result is that SalesYear will have the value Sum({$ <[Date]={}>} [Sales]).

What you can do instead is this:

set SalesYear=Sum({$ <[Date]={@(=@(test))}>} [Sales]);

let SalesYear=replace('$(SalesYear)','@','$');


Or this:


LET SalesYear = 'Sum({$ <[Date]={$' & '(=$' & '(test))}>} [Sales])';


talk is cheap, supply exceeds demand
Not applicable
Author

Thank You,

Your answer is very helpful. You've right :

Since test is not defined the result is nothing.

At first I would prefer the second solution, because you define your expression directly.

But, if you want to had some restrictions you'll have to had chr(39) everyway.

Example, add "City" restriction:

LET SalesYear = 'Sum({$ <[Date]={$' & '(=$' & '(test))}, [City]={' & chr(39) & 'Washington' & chr(39) & '}>} [Sales])';

Is interpreted as :

Sum({$ <[Date]={$(=$(test))}, [City]={'Washington'} >} [Sales])';

So I prefer the first way which is more readable :

set SalesYear=Sum({$ <[Date]={@(=@(test))} , [City]={'Washington'} >} [Sales]);

let SalesYear=replace('$(SalesYear)','@','$');

Thank you for your help.