A variable in Qlik Sense is a named entity, containing a data value. When a variable is used in an expression, it is substituted by its value or the variable's definition.
The variable x contains the text string Sum(Sales).
In a chart, you define the expression $(x)/12. The effect is exactly the same as having the chart expression Sum(Sales)/12.
However, if you change the value of the variable x to for example Sum(Budget), the data in the chart are immediately recalculated with the expression interpreted as Sum(Budget)/12.
It is not recommended to name a variable identically to a field or a function in Qlik Sense. But if you do, you must know how to use them in an expression.
The string XXX represents a field, a variable, a function, or a measure. XXX will be interpreted as one of these depending on how you create the expression.
|Expression||XXX interpreted as|
|XXX||measure, variable, or field|
|Count(XXX)||field or variable|
There are several ways to use variables with calculated values in Qlik Sense, and the result depends on how you define it and how you call it in an expression.
This example requires the following data is loaded in the data load editor:
Let's define two variables, from the variables overview:
- Name vSales Definition'Sum(Sales)'
- Name vSales2 Definition'=Sum(Sales)'
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,