ON THIS PAGE
A variable in QlikView is a container storing a static value or a calculation, for example a numeric or alphanumeric value. When you use the variable in the document, any change made to the variable is applied everywhere the variable is used. Variables are defined in the script using the script editor, where the variable acquires its value from a Let, Set or other control statements in the load script.
If the first character of a variable value is an equals sign ' = ' QlikView will try to evaluate the value as a formula (QlikView expression) and then display or return the result rather than the actual formula text.
When used, the variable is substituted by its value. Variables can be used in the script for dollar sign expansion and in various control statements. This is very useful if the same string is repeated many times in the script, for example, a path.
Some special system variables will be set by QlikView at the start of the script execution regardless of their previous values.
When defining a variable, the syntax:
let variable = expression
is used. The Set command assigns the text to the right of the equal sign to the variable, whereas the Let command evaluates the expression.
Variables are case sensitive.
let vToday = Num(Today()); // returns the date serial number of today.
There are several ways to use variables with calculated values in QlikView, and the result depends on how you define it and how you call it in an expression.
In this example we load some inline data:
Let's define two variables:
In the second variable, we add an equal sign before the expression. This will cause the variable to be calculated before it is expanded and the expression is evaluated.
If you use the
If you add a dollar-sign expansion and call
Finally, if you call
As you can see,