Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
robinrouleur
Partner - Creator
Partner - Creator

Reusable Expression Problem

I've managed to create the following reusable expression in the Document's Variable Overview editor but I can't work out how to define it using a LET/SET statement in the load script.  The problem is the requirement for single quotes arount the $1 argument.  I've tried every alternative for avoiding literal quotes that I can think of but nothing works.  Can anyone help?

Chr(40)&Round(100*Sum($(='$1'&vShowDays))/Sum(ServiceRequests),1)&Chr(37)&Chr(41)

The expression takes an argument, eg "Reprocessed" and adds the postfix in the variable "vShowDays" ("14" or "60") to get the actual dimension name, eg "Reprocessed14".  It then sums it, converts to % and wraps the result in "(result%).  It works perfectly when created in the Variable Overview editor, I just can't find a way to define it in the load script?

Robin

1 Solution

Accepted Solutions
Gysbert_Wassenaar

Try this:

SET vMyVar = Chr(40)&Round(100*Sum(@(='@1'&vShowDays))/Sum(ServiceRequests),1)&Chr(37)&Chr(41);

LET vMyVar = Replace('$(vMyVar)','@','$');


talk is cheap, supply exceeds demand

View solution in original post

4 Replies
Mark_Little
Luminary
Luminary

Hi,

Have you tried.

LET ETest = 'Chr(40)&Round(100*Sum($(='$1'&vShowDays))/Sum(ServiceRequests),1)&Chr(37)&Chr(41)';

then $(ETest) when using it.

Mark

Gysbert_Wassenaar

Try this:

SET vMyVar = Chr(40)&Round(100*Sum(@(='@1'&vShowDays))/Sum(ServiceRequests),1)&Chr(37)&Chr(41);

LET vMyVar = Replace('$(vMyVar)','@','$');


talk is cheap, supply exceeds demand
robinrouleur
Partner - Creator
Partner - Creator
Author

Thx Mark,

That resuilts in: Chr(40)&Round(100*Sum()/Sum(ServiceRequests),1)&Chr(37)&Chr(41)  ie null inside first Sum().

I think this is because the single qiuotes are interpreted as string delimiters so we have two strings with a naked $1 in between.  The $1 and the enclosing $ expansion are both evaluated during the LET assignment and since $1 is not defined the $ expansion results in null.  The key problem seems to be that there is no way to prevent $ expansions from being evaluated during a SET/LET.

robinrouleur
Partner - Creator
Partner - Creator
Author

Yep, that works Gysbert, Thank You!