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

Announcements
April 13–15 - Dare to Unleash a New Professional You at Qlik Connect 2026: Register Now!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Storing Set Analysis to Variable

I have an expression that calculates the amount per Report Date.

Sum({$<%Report_Date_Id = {$(=Max(%Report_Date_Id))}, Year = , Quarter = , Month = >} [Amount])

I would like to save the set analysis expression (just the point in time expression) into a variable since I will need it in multiple places in the document and possibly on other documents too.   I tried the following but none of them works

set vCurrentPeriod = %Report_Date_Id = {$(=Max(%Report_Date_Id))}, Year = , Quarter = , Month =;

OR

set vCurrentPeriod =  '%Report_Date_Id = {$(=Max(%Report_Date_Id))}, Year = , Quarter = , Month ='

My goal is to be able to do this on the expression:

=Sum({$<$(vCurrentPeriod)>} [Amount])

Any help is greatly appreciated.

1 Solution

Accepted Solutions
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Try

LET vCurrentPeriod = '%Report_Date_Id = {$' & '(=Max(%Report_Date_Id))}, Year = , Quarter = , Month =';


talk is cheap, supply exceeds demand

View solution in original post

7 Replies
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Try

LET vCurrentPeriod = '%Report_Date_Id = {$' & '(=Max(%Report_Date_Id))}, Year = , Quarter = , Month =';


talk is cheap, supply exceeds demand
preminqlik
Specialist II
Specialist II

press ctrl+alt +v

and create variable over there and doesnot give = sigh before

=%Report_Date_Id = {$(=Max(%Report_Date_Id))}, Year = , Quarter = , Month =  -->>>> wrong method

%Report_Date_Id = {$(=Max(%Report_Date_Id))}, Year = , Quarter = , Month =  ------>>Correct method

now u can use

Sum({$<$(vCurrentPeriod)>} [Amount])

Not applicable
Author

Thanks Kumar I was able to make this work using this approach.  I wanted to save this in a .qvs file so I'll have to do the assignment in script.

Not applicable
Author

Thanks Gysbert Wassenaar this solved my problem.  I did notice that when I was using the SET, the value stored when I look at the variable overview screen is different than what I assigned in the script.  It looks like this...

vCurrentPeriod = '%Report_Date_Id = {}, Year = , Quarter = , Month =

I don't know what's happening but it is dropping the dollar expansion expression inside the curly braces.  But using LET and breaking it into 2 strings somehow worked.  Would you explain the logic behind that?

preminqlik
Specialist II
Specialist II

then once try this

set vCurrentPeriod = '%Report_Date_Id = {$(=Max(%Report_Date_Id))}, Year = , Quarter = , Month =' ;

or else

write in excel and peek it from there

IAMDV
Master II
Master II

Hi,

You can use ASCII values along with LET statement. Something like this...

LET vMyExpression = 'Sum({<%Report_Date_Id = {' & Chr(36) & '(=Max(%Report_Date_Id))}, Year = , Quarter = , Month = >} [Amount])';

Thanks,

DV

www.QlikShare.com

Not applicable
Author

I had this originally but it does not work.

set vCurrentPeriod = '%Report_Date_Id = {$(=Max(%Report_Date_Id))}, Year = , Quarter = , Month =' ;