Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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)'),'^','@');
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)'),'^','@');
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
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.