Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
salezian
Creator
Creator

Set and set analysis

Dear Qlik Gurus,

I wanted to use following statement in script

set vMaxDate='[Reference Date]={"$(=max([Reference Date]))"}';

to use variable in set analysis.

The weird thing is that the resulting value of the variable after reloading is

[Reference Date]={""}

I completely don't understand why. I always thought that set stores values literally, but it looks like Qlik is trying to execute the function max.

Thanks in advance

BR

M.

1 Solution

Accepted Solutions
jonathandienst
Partner - Champion III
Partner - Champion III

Because the $() expansion executes before the Set statement. You need to defer the expansion, like

Let vMaxDate = '[Reference Date]={"$' & '(=max([Reference Date]))"}';

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein

View solution in original post

4 Replies
Anil_Babu_Samineni

How your set expression looks like in UI?

Best Anil, 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
jonathandienst
Partner - Champion III
Partner - Champion III

Because the $() expansion executes before the Set statement. You need to defer the expansion, like

Let vMaxDate = '[Reference Date]={"$' & '(=max([Reference Date]))"}';

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
jcampbell474
Creator III
Creator III

You can try calling the max reference date first, then peek at the value.


TempMaxDate:

LOAD

max([Reference Date]) as maxRefDate

Resident [yourtable];


Let vMaxRefDate=peek('maxRefDate');

Drop Table TempMaxDate;


(You may need to throw some date formatting in there - depending on your data.)

salezian
Creator
Creator
Author

Thanks Jonathan. That was it. I've used replace function

set vMaxDate = '[Reference Date]={"@(=max([Reference Date]))"}';

let vMaxDate =replace(vMaxDate,'@',$')


All the best.