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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Variable declaration on Script

Hi Community,

I have a simple problem that i can't resolve.

I want to put in my script the declaration of a variable that includes another variable:

    Set vCurrentWeek = "max({<[Calendar-Year]={$(v_MaxYear)}>} [Calendar-Week])";

And i want that when i recompile this script, in the variable declaration appear the $(v_MaxYear) literally, not expanded with the value.

Result:

Sin título.png

Expected:

Sin título.png

It's posible?

Thanks in advance,

Ivan.

1 Solution

Accepted Solutions
rubenmarin

Hi Ivan, to avoid that you can replace the $ by another symbol, and load it using 'LET' and Replace(). Check this answer by Marcus Sommer: Re: Setting a variable in script...

And as a bonus, from the same author: Variables

In your case it can be:

Let vCurrentWeek = Replace('max({<[Calendar-Year]={#(v_MaxYear)}>} [Calendar-Week])', '#', '$');


The same can be used with simple quotes (if needed):

Let vCurrentWeek = Replace(Replace('max({<[Calendar-Year]={|#(v_MaxYear)|}>} [Calendar-Week])', '#', '$'), '|', Chr(39));

View solution in original post

4 Replies
rubenmarin

Hi Ivan, to avoid that you can replace the $ by another symbol, and load it using 'LET' and Replace(). Check this answer by Marcus Sommer: Re: Setting a variable in script...

And as a bonus, from the same author: Variables

In your case it can be:

Let vCurrentWeek = Replace('max({<[Calendar-Year]={#(v_MaxYear)}>} [Calendar-Week])', '#', '$');


The same can be used with simple quotes (if needed):

Let vCurrentWeek = Replace(Replace('max({<[Calendar-Year]={|#(v_MaxYear)|}>} [Calendar-Week])', '#', '$'), '|', Chr(39));

jonathandienst
Partner - Champion III
Partner - Champion III

Its called 'deferring the $ expansion'.

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

Set vCurrentWeek1 = max([Calendar-Year])

Set vCurrentWeek = Sum({<[Calendar-Year] = {"=$(vCurrentWeek1)"}>}Sales)


Good Luck

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
Not applicable
Author

Thanks all for the quick replies,

It works perfectly, thanks rubenmarin

BR,

Ivan