Working with variables and expressions in your PixelPerfect template
You can add variables from the Qlik Sense app to your PixelPerfect template to create dynamic content. Expressions using Qlik Sense syntax can be added directly, allowing you to store and use individual calculations in reports.
Variables and expressions can be added as usable data bindings from the Field List menu.
When to use them
Variables and expressions are useful to add to your report. Here are some examples:
-
Use a scripted variable to store the date of the last time the app was reloaded. This could be inserted on the front page of the report.
-
Add an expression to calculate a key metric, such as total sales. Then, combine the expression into native PixelPerfect text to represent data using natural language and PixelPerfect formatting.
Adding a variable
You can add a variable that exists in the Qlik Sense app as a data binding.
Do the following:
-
Open the Field List menu available from the right-side panel in the designer.
-
Click the plus icon next to Variables.
-
Select the Qlik Sense variable you want to add. Click the icon next to it.
The data binding is added.
Adding an expression
You can add Qlik Sense expressions directly as data bindings.
Do the following:
-
Open the Field List menu available from the right-side panel in the designer.
-
Click the plus icon next to Expressions.
-
Select the Qlik Sense variable you want to add. Click the icon next to it.
The data binding is added.
Example - Using a variable to display date of last app reload
Refer to the example app sources here: Example materials - In-app reporting. Upload the app and data files into a space, and then reload the app. You are ready to complete the example.
In this example, we use Qlik Sense variables to compose a text string representing the date on which the app data was last reloaded.
Do the following:
-
Create a new PixelPerfect template.
-
Open the Field List in the designer.
-
Expand Variables. Click the plus icon to add a new variable.
-
Click the plus icon next to vLastReloadYear. This is a scripted variable from the app. The variable contains the expression =year(now()) and is only updated when the app reloads.
-
You are brought back to the main Field List menu. Click the plus icon next to Variables.
-
Click the plus icon next to vLastReloadMonth. This is a scripted variable from the app. The variable contains the expression =month(now()) and is only updated when the app reloads.
-
You are brought back to the main Field List menu. Click the plus icon next to Variables.
-
Click the plus icon next to vLastReloadDay. This is a scripted variable from the app. The variable contains the expression =day(now()) and is only updated when the app reloads.
-
From the toolbox panel on the left side of the designer, drag a Label object onto the TopMargin1 band in your template.
-
Select the label. Click the bold f icon near the label to open the Expression Editor.
-
In the Expression Editor, enter the following expression:
Concat('App last reloaded: ', [vLastReloadYear], '-', [vLastReloadMonth], '-', [vLastReloadDay])
-
Increase the width of the label so that all text can be displayed on a single line.
-
Customize and style the label properties if desired.
-
In the top right corner, click Save template.
-
Click Preview report. Download the report and open it.