Introduction
QlikView variables always start with a $ sign. Local variables give local scope. A local variable shows a reference in the function or block where it is declared. Large Variables override the same variable name in the large scope.
The Global variable gives global scope, in other words it is visible and accessed by the user throughout the program. Global Variables are generally known as static variables.
Scope of Local and Global Variables
A variable's scope depends on the range of the scripts where it is visible. Variables have both local and global scope.
A Local variable has limited scope. The local variable exists only within the block where it is declared. When a block ends the variable is destroyed and all values are lost.
A Global variable exists only one time in a script and this script is visible in every function. They never lose the values that are relatively constant.
Scope of Local and Global variables in QlikView Application
Use the following procedure to creatre a sample for understanding the concept of local and global variables in QlikView.
Step 1: Open the QlikView application
It is the first step, in this step you need to open the QlikView application then go to:
File-> New then this window will be opened.
Step 2: Open Edit Script
The second step is to open the edit script window from File-> Edit Script.
Step 3: Select Database
The third step is to select the database from the Data tab and click on the Connect Button.
Step 4: Data link property window
In this window we select SQL Server and click on the Next Button.
Step 5: Connection tab
In the connection tab enter the server name and user name and password and select the database from your server and click on Test Connection.
- Then you find that the test connection has succeeded and click on the OK button.
- Then click on the OK button.
Step 6: SQL Server login
Then they require a SQL Server login so enter a valid Login ID and Password and click on the OK button.
Step 7: Create select statement
When we click on the Select button on the Data tab then this window will be opened.
- Then this window will be opened and click on the OK button.
Step 8: Code of edit script
After LogIn the SQL Server, edit script windows will be opened and reload it.
Step 9: Save QlikView file
After reloading the edit script, the next step is to save the QlikView file and click on the Save button.
Step 10: Script execution progress
Then the Script Execution progress window will be opened and requires a Login Id and Password and click on the OK button.
Step 11: Sheet property Window
After this process, the sheet property window will be opened. If you want, add a field and select a field from available fields and click on the OK button.
- Then this window will be opened.
Step 12: Add variable
The next step is to add a variable, then go to Setting->Variable Overview from toolbar option.
- Then click on the Add button and add variables.
- Then provide a Definition of variable and again add a new variable.
- Then provide a Definition of another variable and click on the OK button.
- Now you can see Add variables from the Setting->Variable Overview, then this window will be opened and click on the OK button.
Step 13: Select Chart
Now right-click anywhere in the blank main sheet and select New Sheet Object-> Chart, then this window will be opened.
Step 14: General Window
In this window select straight table and click on the Next button.
Step 15: Add dimension
The next step is to add dimensions and click on the Next button.
Step 16: Edit expression Window
In this window we define the QlikView variable with $ and click on the OK button.
- Again add another QlikView variable then click on the Add button.
- Then add another QlikView variable and click on the OK button.
- Now you can see both QlikView variables.
- If you want to change the label name then change it and click on the Finish button.
- Now you can see the table after adding the QlikView variable.
Step 17: Select Text object
Now right-click anywhere in the blank main sheet and select New Sheet Object-> Text Object, then a window will be opened.
Step 18: New Text object window
Now a text object window will be opened then we write text for the text object for the first QlikView Variable and click on the OK button.
- Again add another text object for the QlikView variable and click on the OK button.
- Now you can see that the other text objects will display the total number of Person Ids that we mentioned in the table.
Now here you can see we are using two variables Count and Total Count. The Count variable will display the number of Person Ids in the table and the Total Count variable will display the total number of Person Ids in the table.
Summary
This article described the concept and scope of variables in QlikView applications.