Qlik Sense and QlikView variables can be used to customize Qlik NPrinting reports and emails.
A variable in Qlik Sense or QlikView is a static value that can be:
- a string of text
- a number
- a date
- the evaluated result of an expression
Expressions are identified by an equal sign = at the beginning. When you use a variable in an app or document, any change made to the variable is applied everywhere the variable is used.
Variables can contain complex expressions, user information, or company details. For example, you could have a variable that calculates weekly sales figures by region. You could use a variable in place of a product name that may change in the future. A user name variable could be used to personalize company emails. These types of variables make your reporting more consistent and easier to maintain.
Best practices for variables used in Qlik NPrinting
Variables in Qlik Sense and QlikView are often used in combination with dollar-sign expansions. You should do this when you want to use a variable like a placeholder, instead of a true variable. Variable dollar-sign expansions work by replacing their "text" with the static value of the variable.
For example, you have these two variables in Qlik Sense or QlikView:
- vSales defined as: Sum(Sales)
- vSales2 defined as: =Sum(Sales)
An expression like =$(vSales) can be used in a Qlik Sense chart as a measure or in a QlikView chart as an expression. When the Qlik engine evaluates this expression, it will replace the content of the dollar-sign expansion $(vSales) with the static value of vSales. The static value of vSales is Sum(Sales). So the evaluated final expression will be =Sum(Sales).
Suppose that the total Sum(Sales) is 1560. If you write an expression like =$(vSales2), the Qlik engine will evaluate it, as in the case before, and replace the content of the dollar-sign expansion $(vSales2) with the static value of vSales2. The static value of vSales2 is 1560, because it was defined as an expression. So the evaluated final expression will be 1560.
This means that without a dollar-sign expansion, vSales is a variable that contains the text of Sum(Sales).
If you insert these expressions as two different measures in a Qlik Sense chart or expressions in QlikView, you would see the following results:
As you can see, =$(vSales) results in the partial sum for a dimension value, while =$(vSales2) results in the total sum.
Qlik NPrinting will always consider the static value of the variable, and never its dollar-sign expansion. If you want to evaluate an expression in a variable that does not begin with an = sign, you must change its definition in QlikView or Qlik Sense. If you cannot do that, you must create a second variable that can be defined as the dollar-sign expansion of the original one: vSales3 defined as =$(vSales). If you are using the Qlik NPrinting Designer, you do not have to create another variable. You can use a formula to expand the original variable instead.