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: 
umartareen
Creator II
Creator II

Defining YTD/MTD Set Analysis expression through variables in Edit Script

Hi All,

I have a scenario where I need to define my YTD expressions in the edit script using variables.

Here is what I am doing and I am not getting the output.

Variable / Expression :

LET vFLM_Amount    = 'sum({<[Fiscal Year] = {"$(vMaxYear)"}, [Period Number] = {">=$(vMinMonth) <=$(vMaxMonth)"}>} [Amount])';

where :

LET vMaxYear  = 'max([Fiscal Year])';

LET vMinMonth = 'MinString([Period Number])';

LET vMaxMonth = 'MaxString([Period Number])';

When I try the same expression in a text object, then it works except that I have to replace the double (") with single quotes ('), as the single quotes throw an error when used through edit script.

How can this be achieved ? Help will be appreciated !!

Thanks,

Umar

1 Solution

Accepted Solutions
sunny_talwar

May be try this:

LET vFLM_Amount = '=Sum({<[Fiscal Year] = {"$' & '(vMaxYear)"}, [Period Number] = {">=$' & '(vMinMonth) <=$' & '(vMaxMonth)"}>} [Amount])';

Dollar sign has the tendency to get evaluated in the script and in order to avoid that, break your expressions into parts and see if that works

View solution in original post

17 Replies
adamdavi3s
Master
Master

Hi Umar,

Don't use " (double quotes) use '' (double apostrophe)

LET vFLM_Amount    = 'sum({<[Fiscal Year] = {$(''vMaxYear)''}, [Period Number] = {''>=$(vMinMonth) <=$(vMaxMonth)''}>} [Amount])';

sunny_talwar

May be try this:

LET vFLM_Amount = '=Sum({<[Fiscal Year] = {"$' & '(vMaxYear)"}, [Period Number] = {">=$' & '(vMinMonth) <=$' & '(vMaxMonth)"}>} [Amount])';

Dollar sign has the tendency to get evaluated in the script and in order to avoid that, break your expressions into parts and see if that works

umartareen
Creator II
Creator II
Author

Hi

I worked the solutions provided and unfortunately they do not yirlf the output.

Thanks,

Umar

adamdavi3s
Master
Master

Actually I remeber this from before, try this:

LET vFLM_Amounttmp    = 'sum({<[Fiscal Year] = {~(''vMaxYear)''}, [Period Number] = {''>=$(vMinMonth) <=$(vMaxMonth)''}>} [Amount])'; 

LET vFLM_Amount   = "=replace([vFLM_Amounttmp],'~','$')";

umartareen
Creator II
Creator II
Author

Yield*

Not applicable

Hi Umar,

Might be it will useful to you.


LET vFLM_Amount = '=Sum({<[Fiscal Year] = {"$' & '(vMaxYear)"}, [Period Number] = {">=$' & '(vMinMonth) <=$' & '(vMaxMonth)"}>} [Amount])';

sunny_talwar

How about without the equal sign

LET vFLM_Amount = 'Sum({<[Fiscal Year] = {"$' & '(vMaxYear)"}, [Period Number] = {">=$' & '(vMinMonth) <=$' & '(vMaxMonth)"}>} [Amount])';

umartareen
Creator II
Creator II
Author

Sunny, Thanks for the immediate responses ! It still doesn't work !!

Thanks,

Umar

adamdavi3s
Master
Master

This works for me, see attached

LET vFLM_Amounttmp    = '=sum({<[Fiscal Year] = {~(''vMaxYear)''}, [Period Number] = {''>=~(vMinMonth) <=~(vMaxMonth)''}>} [Amount])';

LET vFLM_Amount  = replace([vFLM_Amounttmp],'~','$');