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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
joris_lansdaal
Creator
Creator

Help - Front-end variables in the script

Hi,

I'm using variables in my report/graphs in order to enhance flexibiity.

(sum({<CurMATFlag={1}>}  $(VarFact))-sum({<LastMATFlag={1}>}  $(VarFact)))/1000*$(VarFactor)

VarFact is a variable for different facts like Volume, Margin etc

VarFactor is a variable for the scale

Now I want to move this expression into the script and use a variable in my graphs

Let MAT_VAR = '(sum({<CurMATFlag={1}>}  $(VarFact))-sum({<LastMATFlag={1}>}  $(VarFact)))/1000*$(VarFactor)';

But now VarFact and VarFactor are static and don't get calculated. I tried several things based on posts of  HIC  https://community.qlik.com/blogs/qlikviewdesignblog/2013/11/04/the-magic-of-variables

but I can't find the right syntax.

Any suggestions?

thanks! Joris

1 Solution

Accepted Solutions
swuehl
MVP
MVP

I believe that's because the dollar sign expansion is getting evaluated in the script, which is not what you want.

There are several methods to avoid this (one could be to load all variables from an excel file, I think there is a sample script in the reference manual that demonstrates this, you can also find the code here in the forum.)

Another approach would be using replace() function to replace an arbitrary dummy character not used in your original string with the dollar sign:

Let MAT_VAR = Replace('(sum({<CurMATFlag={1}>}  ^(VarFact))-sum({<LastMATFlag={1}>}   ^(VarFact)))/1000*^(VarFactor)'),'^','@');

View solution in original post

3 Replies
swuehl
MVP
MVP

I believe that's because the dollar sign expansion is getting evaluated in the script, which is not what you want.

There are several methods to avoid this (one could be to load all variables from an excel file, I think there is a sample script in the reference manual that demonstrates this, you can also find the code here in the forum.)

Another approach would be using replace() function to replace an arbitrary dummy character not used in your original string with the dollar sign:

Let MAT_VAR = Replace('(sum({<CurMATFlag={1}>}  ^(VarFact))-sum({<LastMATFlag={1}>}   ^(VarFact)))/1000*^(VarFactor)'),'^','@');

Peter_Cammaert
Partner - Champion III
Partner - Champion III

IMHO the simplest solution for unwanted script-level dollar sign exapnsion is the mighty concatenation operator '&'. Like in:

Let MAT_VAR = '(sum({<CurMATFlag={1}>} $' &

             '(VarFact))-sum({<LastMATFlag={1}>} $' &

             '(VarFact)))/1000*$' & '(VarFactor)';


Separating the $-sign from the parenthesis is enough to trick the expansion preprocessor. I admit that this doesn't really improve expression readability...


Best,


Peter

trdandamudi
Master II
Master II

As Stefan mentioned, one way is to load the variables from Excel into Qlikview. If you are interested in this concept you can take a look at the attached file which loads the variables from Excel.