Variables in Qlikview | Qlikview for creating data stories

Contents

Introduction

An application with a good Front-end and a poor Back-end is like Beauty without a brain. At first it amazes you, but over time it irritates you. Secondly, an efficient back-end with a poor front-end may not encourage users to use the application. In today's world, you need excellence in both aspects.

Regrettably, many people associate data visualization only with front-end engineering. In today's article, I want to highlight what back-end engineering is like in the case of QlikView and how it can add tremendous power to your data stories.

The natural progression in a programming language

If you have learned to code in any language, would you have experienced this progression yourself.

the first stage of learning a language is to understand its syntax, the ways to print results, perform mathematical calculations, etc. In this stage, normally nothing complex is done. As usual, this is not very exciting or useful. After all, you don't learn a programming language to calculate 2 + 3!

the second stage of learning a language is when you start using variables to perform some of the more complex tasks. With the use of variables, can create generic logic, which is more complicated and useful. Then, if you want to compare 2 columns with a million numbers each, you can't do it unless you use variables (It may be that you can, not me!). The beauty of the process is that once you learn to use the variables, It is impossible to think that there was even a stage 1 involved in the learning process!

There are a few more stages in learning a new programming language, but in today's article we will focus on what I just mentioned as the second stage of any programming language: the use of variables. If you are a newbie to QlikView, you must first learn the basics of our learning path: resource to learn Qlikview from scratch and become an expert

Real life situation: Variables to my rescue!

I started using QlikView at the beginning of 2012 and i fell in love with him. We had a team of passionate developers and for the next 6 months (with many dark nights), we were able to replace the traditional clumsy Excel reports / Access en un agradable panel de control QlikView para todo el proceso de ventas de nuestra organización. We were now the envy of other intelligence units in our organization and we were called a successful transition across the Organization..

In september 2012, the sales director called me. This was the time of sales planning for next year. Then, I expected him to ask the plans for the same. And I was well prepared for this. During years, we had created an Excel based application that simulated a lot of scenarios and then spit (literally) goals for all sales staff.

Then came the bomb! The sales manager said that this time he wants the planning to take place in our QlikView application. Said he wanted a new sheet on our board, donde el personal de ventas pudiera ingresar parameters para sus esfuerzos (for instance, receive 10 sales calls per day) and the app provides an estimate of where they would end up taking into account seasonality and past trends.

I had no idea how to do this in QlikView, so i heard it. I didn't want all the efforts of the past 6 months were up and people were reverting to older ways of running business intelligence. Fortunately, I found variables and their use to run what-if scenarios, that we continue to build in our application.

What is a variable? What are the methods to create it?

Variables store data (static or calculated) of any type (numbers, chain, booleans, floating) and they are referenced using expressions or directly using their name. There are some basic rules of the variable naming convention in QlikView:

Rule 1: Siempre que creamos una variable para el valor estático, we prefix the name of the variable with “v”(Lowercase).

Rule 2: Whenever we store an expression in a variable, we prepend the name of the variable with “me”(Lowercase).

After the first character, we must keep the names relevant to make it developer friendly. There are several methods to create a variable. The most used are:

Method 1: Entering the menu -> setting / variables overview

Method 2: Using SET and LET statements.

Let's see them one by one:

Method 1:

Go to the Settings menu -> Click Variable Overview

create_variable_3-6993826

Note: You can also define a variable with an expression.

Method -2:

Whenever you start a new document and proceed to edit the script, you must have noticed that there are some predefined values ​​that QlikView loads depending on your system configuration. Right ?

This is because these are the variables that QlikView creates using Set statement. You can also use “Put on”Declaration to define variable (s) in the script.

predefined_values-9678618

Let's see how we do it. Look at the following variable definition syntax:


Syntax: Set Variable_Name=Value;
Example: Set vPrevYr="2014";

Another method of creating variables is to use “Let” statement. Let statement evaluates the expression on the right side of ‘=’ and assign it to the variable on the left side of ‘=’.

Syntax: Let Variable_Name = Expression;

Example: Flight vTest = 5 + 8;

If you are going to use Put on declaration to store the output of the expression in a variable, will store the expression as a value. I will show the detailed effect of defining a formula with Let Y Put on statement in next sections.

Example: Set vTest1=5+8;

In the screenshot below, can see all defined variables (vPrevYr, vTest, vTest1) after running the script. In the same way, here you can also define / find new variables.

variable_list1-4681834

Read also: How to implement incremental loading in qlikview?

How can we access the variable?

The value of a variable can be accessed using the equal sign (=). If the variable has the prefix “=”, QlikView tries to evaluate the value as a formula (QlikView expression) and then display or return the result instead of the actual formula text.

Let's understand it by accessing the variable created previously “vTest“(Created with Let) Y”vTest1”(Created with Set).

Creemos un objeto de text box y pongamos una expresión como “= VTest” and similarly in another textbox, we put “= VTest1” (As shown below).

expression-1961646

Just observe that, the variable (vTest) created using “Let”It has been well evaluated. Conversely, the variable (vTest1) created with “Put on” has has not been evaluated. This is the difference between creating a variable using the Set or Let statement.

Now, to evaluate the variable vTest1, we can use Dollar sign expansion (DSE). It is a method to evaluate a formula. Let's look at this method of using dollar sign expansion. What's more, this is also a standard way to access a variable in QlikView.

Syntax: $(variable_Name)

Now I will access the variable “vTest1 ″ and check the output.
dollar_sign_expansion-6332321

Read also: The concept of synthetic keys in Qlikview – Simplified!

What are the most common uses of the variables?

Variables are the mainstay of data visualization software like Qlikview, D3.js, etc. Optimizing the use of variables always reduces application development time. Let's look at some common uses of variables:

  1. Portability: Variables are used when we want to store values ​​and use them in multiple objects / graphs inadvertently typing those values ​​again. Variables are also used when we want to perform dynamic calculations. For instance: A variable created to represent the previous year as “vPrevYr = $ (= Max (Year) -1)”, refers to a dynamic calculation based on the current selection and can be accessed by all document objects.
  2. Use in chart objects: We can make use of variables in charts in multiple places using:
    • Dynamically limit the dimension: I answered a related question in discussion portal regarding charting functionality in QlikView. I solved it by creating a variable to hold user input (how many categories do you want to see) usando el cuadro de entrada y luego usé esta variable en la pestaña de límite de dimension del gráfico. You can see the complete solution here.

      charts-7931829

    • Enable or disable dimension conditionally / expression / object: Think of a scenario where you have segregated the objects in your graphics into two categories. Later, you want to show only one category at a time. This can be done effortlessly using a button or a variable. Let's follow the steps below to do this:
        • Paso 1: create a variable “vVisible"And assign the value as zero (0).
        • Paso 2: Create a button and then go to properties -> Action -> Type of action (Expernal) -> Action (Set variable)
          button-8638883
        • Paso 3: Assign the value to the variable as zero (0) and give the name to the variable as "Category1". Similarly, create another variable like “Category2” and assign the value of the variable (vVisible) What 1.
        • Paso 4: Select the chart objects and go to properties -> Design -> Conditional. Depending on the category to which this chart belongs, apply the condition for the variable “vVisible“. Repeat this process for all chart objects that you want to enable or disable based on category.

      layout-7017382

      • Paso 5: Now click on any Category button, graphics related to that category will be displayed only.
  1. And if the analysis: We can use the variable in the parse expression and if also using “Input box” O “Sliding object ". In such cases, we take the value of the variable of these objects (Entry, Slider control) and we use them in expression.
  2. In expressions (Set Analysis y Aggr): You can use variable expression beforehand as Set Analysis, Aggr () and others. To get more details on these expressions, you can follow these articles (Set analysis, AGGR ())

Apart from the uses mentioned above, we can also use variables for incremental data loading and in various scripting methodologies to improve our data models.

Final notes:

In this article, we analyze the importance of the variables, the methods to create them and the common uses of variables in daily development. Basically, we have analyzed two methods (Set & Let y Variable Overview) to create them.

If I summarize the most common use of the variable, then it would be developing expressions using other graphics objects as input box, slider, text box, buttons and others. My advice would be to use the variable in your control panel. It reduces the static nature of the board and you can change the value in the expression by changing it in one place.

Hope this article helped you get the details of variables in QlikView. We would love to hear from you.. Did you find it useful? Feel free to post your thoughts via the comments below..

If you like what you have just read and want to continue learning about analytics, subscribe to our emails, Follow us on twitter or like ours page the Facebook.

Subscribe to our Newsletter

We will not send you SPAM mail. We hate it as much as you.

Datapeaker