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.
![After clicking New option]()
Step 2: Open Edit Script
The second step is to open the edit script window from File-> Edit Script.
![window of edit Script]()
Step 3: Select Database
The third step is to select the database from the Data tab and click on the Connect Button.
![select database]()
Step 4: Data link property window
In this window we select SQL Server and click on the Next Button.
![data link]()
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.
![test connection]()
- Then you find that the test connection has succeeded and click on the OK button.
![Confirm box]()
- Then click on the OK button.
![ok box]()
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.
![SQL server]()
Step 7: Create select statement
When we click on the Select button on the Data tab then this window will be opened.
![select statement]()
- Then this window will be opened and click on the OK button.
![create select]()
Step 8: Code of edit script
After LogIn the SQL Server, edit script windows will be opened and reload it.
![reloading]()
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.
![save file]()
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.
![Script execution]()
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.
![main sheet]()
Step 12: Add variable
The next step is to add a variable, then go to Setting->Variable Overview from toolbar option.
![add variable]()
- Then click on the Add button and add variables.
![variable]()
- Then provide a Definition of variable and again add a new variable.
![definition]()
- Then provide a Definition of another variable and click on the OK button.
![def]()
- Now you can see Add variables from the Setting->Variable Overview, then this window will be opened and click on the OK button.
![final variable]()
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.
![select chart]()
Step 14: General Window
In this window select straight table and click on the Next button.
![general window]()
Step 15: Add dimension
The next step is to add dimensions and click on the Next button.
![dimension window]()
Step 16: Edit expression Window
In this window we define the QlikView variable with $ and click on the OK button.
![QlikView variable]()
- Again add another QlikView variable then click on the Add button.
![variable2]()
- Then add another QlikView variable and click on the OK button.
![QlikView variable1]()
- Now you can see both QlikView variables.
![final variable1]()
- If you want to change the label name then change it and click on the Finish button.
![label name]()
- Now you can see the table after adding the QlikView variable.
![final]()
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.
![select text]()
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.
![text object]()
- Again add another text object for the QlikView variable and click on the OK button.
![text object1]()
- Now you can see that the other text objects will display the total number of Person Ids that we mentioned in the table.
![last window]()
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.