Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements

Breathe easy -- you now have more time to plan your next steps with Qlik!
QlikView 11.2 Extended Support is now valid through December 31, 2020. Click here for more information.

robinrouleur
New Contributor III

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
MVP & Luminary
MVP & Luminary

Re: Reusable Expression Problem

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
4 Replies
mark6505
Valued Contributor III

Re: Reusable Expression Problem

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

MVP & Luminary
MVP & Luminary

Re: Reusable Expression Problem

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
New Contributor III

Re: Reusable Expression Problem

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
New Contributor III

Re: Reusable Expression Problem

Yep, that works Gysbert, Thank You!