Contact Us

Kockpit is here to help you

Business Form

Mastering Basics of Qlik Sense Set Analysis

Suppose a KPI displays Total Sales across all years. Now, if you make a selection on Year (say 2022), the KPI will consequently display Sales for 2022. 


But what if you wanted a KPI to display sales for 2022 without ever selecting it, or wanted a KPI to always display Total Sales across all years regardless of any selections made? 


This is where Set Analysis comes into play. It is a powerful front-end tool that allows one to create a custom subset of data that differs from the actual selection. 


Let's explore how Qlik Sense Set Analysis can help you tailor your data visualization to your exact needs. 


Set Analysis Syntax in Qlik Sense 


Set Analysis is the analysis performed on a data subset after a certain expression is written. This expression is known as the Set Expression.


The Set Expression syntax can be really daunting, however, this article will help you navigate through it with ease. 


A Set Expression can be written in two ways: 


  • Inner Set Expression 

  • Outer Set Expression 


Syntax for Inner Set Expression in Qlik Sense


In an Inner Set Expression, the set expression is added inside an aggregation function. 


SUM({<Product = {‘Laptop’}>} Sales) / COUNT(Years)


  • The bold text is the Set Expression. It translates to ‘just choose products with the name Laptop.’ 


  • { } → Curly Braces are used to initiate ({) and end (}) the Set Expression. 


  • < > → The Set Modifier comes within these symbols. In the above example, Product = {‘Laptop’} is the set modifier.


NOTE: The Set Expression will only be applied to the field of Sales.


Syntax for Outer Set Expression in Qlik Sense


In an Outer Set Expression, the set expression precedes the aggregation. 


{<Product = {‘Laptop’}>} SUM(Sales) / COUNT(Years)



  • The terminologies are akin to the Inner Set Expression.


  • In the case of Outer Set Expression, all the fields (Sales, Years) in the above will inherit the Set Expression. 


A generic Set expression contains the following components. 


Let's explore these in detail. 


Set Identifiers in Set Analysis Qlik Sense 


Set Identifiers are used to represent the Selection Criteria that the Set Analysis should consider. They need to be mentioned right after the opening curly brace ( { ).


The below table summarizes all the Selection Criteria that can be used. 




Use Case of Set Identifier {1} in Qlik Sense 


This Set Identifier is used to ignore all the selections made in the dashboard, i.e. it's used when a static value is to be shown. 


Question: 

Imagine you are working with a sales dashboard in Qlik Sense, and your organization wants to track and visualize the performance of a specific product category (e.g., “Electronics”) compared to the overall sales across all product categories. 


Solution: 

According to the question, we need 2 KPIs: 


  • The first one that shows the Total sales including all product categories, disregarding selections.

  • The second one that shows the Sales of a selected product category. 


Following is the Set Expression for the first and second KPI: 


SUM({1} Sales)  // 1st KPI


SUM(Sales) // 2nd KPI



Notice how the KPI on the left doesn’t change even though a selection has been made, while the second KPI reflects the changes according to the selection. 


Demonstration of Set Identifier {$1}, {$_1}, {$} in Qlik Sense


The Set Identifier {$1} is used to get the value of the forward selection, while {$_1} is to get the value of the previous selection.  


Similarly, {$2} means go two selections forward while {$_2} means go two selections backward, and so on. 


In other words:

  • {$1} is akin to the ‘Step Back’ Button.  

  • {$_1} is akin to the ‘Step Forward’ Button. 


NOTE: {$1} and {$_1} are rarely used in Qlik Sense.


Set Identifier {$} refers to the current selection. It is the default identifier, meaning an explicit mention isn’t necessary.


Below is the Set Expression along with the output. 

SUM({$1} Sales) // Get previous selection


SUM({$_1} Sales) // Get forward selection


SUM(Sales) // is same as SUM({$} Sales)




In essence, Set Identifiers in the Qlik Sense, including {1}, {$1}, and {$_1}, play a pivotal role in shaping data analysis by allowing users to control the context of selections. Utilizing these identifiers, users can create dynamic KPIs, such as tracking overall sales regardless of selections ({1}), retrieving values from forward or backward selections ({$1}, {$_1}), and referencing the current selection state ({$}).


Set Operators in Set Analysis Qlik Sense 


Set Operators are operations performed on two or more subsets of data to obtain a single set, i.e. the combination of those sets. 


There are 4 Set Operators in Qlik Sense Set Analysis: 


Union Set Operator in Qlik Sense


It simply produces a union of two sets. 


Question: 


Suppose you are managing a financial dashboard in Qlik Sense, and your company is interested in monitoring country-wise sales. The objective is to design a visual representation that illustrates sales for those countries that begin with either an ‘S’ or end with ‘land’. 


Solution: 

We require two sets according to the question: 

  • Set 1 → Containing countries beginning with an ‘S’.

  • Set 2 → Containing countries ending with ‘land’.


Logically, we will have to combine Set 1 and Set 2 i.e., take a union of both sets. 


Below is the code to achieve it, along with the output. 


SUM({<Sales = {“S*”} + {“*land”}>} Sales)



The Left KPI shows total sales for country names beginning with an ‘S’ and ending with ‘land’ while the Right Table is to verify the total sales of the Left KPI. 

Intersection Set Operator in Qlik Sense


As the name suggests, it chooses the common values between two sets and ignores the rest. 


Question: 

Calculate the total sales for the intersection between a Bookmark and the Current Selection.


Solution: 

Below is the code. 


SUM({<$ * BM01>})


 

The Exclusion Set Operator in Qlik Sense 


This operator excludes the selections made, meaning values not present in the selection are considered. 


The below representation will elaborate on the above statement! 



As you can see, when HR is selected the unselected values i.e. Engineering, Finance, and Sales are displayed in the Right Text Box. 


Question: 

Create a functionality where the manager can visualize the total sales of those customers that are not included in a selection. 


Solution: 

Below is the code and its result. 


SUM({1-$} Sales) 



This functionality will help if there are numerous values in a field and only a few are to be excluded. Therefore, the few that aren’t required can be excluded by selection. 


Symmetric Difference Set Operator in Qlik Sense


Symmetric Difference basically means the complement of an Intersection. 


Question: 


Let's apply the symmetric difference operator to the question mentioned in the Intersection Set Operator section.  


Below is the code: 

SUM({$ / BM01})


In summary, Qlik Sense Set Analysis employs four key set operators: Union, Intersection, Exclusion, and Symmetric Difference. These operators enable precise data analysis, allowing users to combine, extract, and visualize subsets based on specific criteria, enhancing the flexibility and depth of insights within financial dashboards and analytics scenarios.


Set Modifiers in Set Analysis Qlik Sense


Set Modifier is the crux of a Set Expression, thereby, making it a vast topic. However, to simplify it, let’s break it down into several points. 


  • Set Modifiers make modifications to the current selection.


  • They are added to the Set Expression after the Set Identifier. 

 

  • Modifications are made using field names.


  • A search mask enclosed in curly braces ‘{ }’ and is given to the Right Hand Side of the field name separated by an equal sign ‘=’. 

COUNT({< field_name = {search_mask}>} field_name)



  • The search mask filters out all the values within the field.  


  • The search mask could be one of the three: 


  1. Numeric Value:  

SUM({1<Year = {2020}>} Sales) // Sales for 2020



  1. A value in the field:  

SUM({1<Product = {‘Laptop’}>} Sales)



NOTE: Values are Case-Sensitive, meaning ‘Egg’ and ‘egg’ are not the same. 



  1. A formula/ Qlik function/ Wildcard: 

SUM({<Country = {“=SUM(Sales) > 100000”}>} Sales)

// Total Sales for countries having sales greater than 100k


NOTE: An equal sign ‘=’ comes before the Qlik Aggr Function and the search mask has to be enclosed in double quotes “ ”.  



  • The Set Modifier needs to be placed within ‘< >’. 


  • There can be more than 1 Set Modifier, for example: 

COUNT({<Year = {2019}> + <Country = {‘India’}>} Customers) 


Element Functions in Qlik Sense

Element Functions are used when a nested set expression is required. There are two types of Element Functions: 


  1. P( ) → Possible Values 

Func_Name({1<field_name =   P({$<field_name={search_mask}>}) >})



  1. E( ) → Exclude Values 

Func_Name({1<field_name =   E({$<field_name={search_mask}>}) >})



Let’s take a look at an example for each. 


Possible Values P() in Qlik Sense


Question: 

Calculate the total sales of customers that have purchased a Laptop. 


Solution: 

At first glance, this question may seem benign. So let's solve it as it may seem. 


Below is the benign code:  

SUM({<Prodcut = {‘Laptop’}>} Sales)



In reality, the above code will produce the total sales for Laptops (4.8k), however, we require the total sales of customers who have purchased a laptop (6.4k). 


So let's break down the question into two parts. 


  1. Find Customers who have purchased a Laptop. Below is the set expression to achieve it. 

({<Product = {‘Laptop’}>} Customers)



  1. Find the total sales made by those customers. Suppose the above code returns customer names as “Abdullah”, “Gaurav”, and “Siddesh”. Then the set expression will be: 

({<Customers = {‘Abdullah’,’ Gaurav’, ‘Siddesh’}>} Sales)



Now, when we merge both codes, we get: 

SUM({<Customers =                              P({<Product = {‘Laptop’}>} Customers)>} Sales)



Do the same for Excluded Values, i.e., E() and you will get the total sales of customers who haven’t purchased a Laptop. 


Below is the code along with the output snippet. 

SUM({<Customers =                              P({<Product = {‘Laptop’}>} Customers)>} Sales)




Conclusion 


Mastering the fundamentals of Qlik Sense Set Analysis opens the door to powerful data manipulation and visualization capabilities. Set Analysis serves as a vital tool for tailoring data representations precisely to meet specific requirements. 


Understanding the syntax, identifiers, operators, modifiers, and element functions empowers users to create dynamic visualizations that remain unaffected by user selections or provide targeted insights based on varied criteria. 


The ability to employ set operators like union, intersection, exclusion, and symmetric difference significantly enhances data analysis possibilities.