Reader small image

You're reading from  Qlik Sense Cookbook. - Second Edition

Product typeBook
Published inAug 2018
PublisherPackt
ISBN-139781788997058
Edition2nd Edition
Right arrow
Authors (3):
Pablo Labbe
Pablo Labbe
author image
Pablo Labbe

Pablo is a Business Intelligence Consultant with over 18 years of experience. In 2008 he was presented to Qlikview, the former product by Qlik and the seed for Qlik Sense. Since that year he was focused on delivering BI solutions in a new way. Now he is the Principal of ANALITIKA Inteligencia delivering BI projects and training focusing on Qlik products and other technologies that embrace the Self-Service BI. He is an active member of the Qlik Community and other social media sites. You can follow him on Twitter - @pablolabbe and LinkedIn.
Read more about Pablo Labbe

Philip Hand
Philip Hand
author image
Philip Hand

Philip Hand is a Senior Business Intelligence consultant who has worked with QlikView in the BI space for over 7 years. Working with Qlik's top partner in the UK, he has implemented end-to-end solutions in a wide variety of enterprises and for large business customers. Philip has great experience and knowledge working across many sectors from the public sector, insurance, and financial services to large retailer and manufacturing businesses.
Read more about Philip Hand

Neeraj Kharpate
Neeraj Kharpate
author image
Neeraj Kharpate

Neeraj Kharpate works as a Senior Business Intelligence consultant at Capventis, a QlikView Elite Partner. Having started his career working as a technical support executive for an aviation ERP, Neeraj embarked on his journey with Qlikview in mid-2007. He is a certified Qlikview designer, developer, and trainer. Neeraj has been closely following the developments in Qlik Sense ever since it was launched in 2014 and is extremely excited about the future of this product. Neeraj has completed his Masters in Business Administration from the Norwich Business School, University of East Anglia. He also has a diploma in Management Consulting from the Chartered Management Institute, UK.
Read more about Neeraj Kharpate

View More author details
Right arrow

Chapter 8. Advanced Aggregation with AGGR

In this chapter, we will focus on understanding what the AGGR function is and how to use it. The following topics will be covered:

  • Using nested aggregations
  • Using Rank() with Aggr
  • Combining set analysis with Aggr
  • Creating an ABC analysis

Introduction


This chapter will focus on the use of the special function Aggr. In very specific cases, we need to calculate summaries over a group of dimensions.

Aggr is the only function that can enclose or be enclosed by another aggregation function.

Using nested aggregations


We know how to use several aggregation functions such as sum, max, min, and avg. When used in a measure of a chart or table, they aggregate values over the dimension stated in that chart or table.

Sometimes, you need to create a second aggregation based on the result of the first. An example could be the value and the name of the country with the most customers. This can be done using Aggr, combined with the Max() and Firstsortedvalue() functions.

Getting ready

Create a new Qlik Sense application, and load the following script that gives information on sales per country:

LOAD * INLINE [ 
Region, Country, No of Customers, Sales 
Americas, Uruguay, 200, 56000 
Europe, France, 900, 252000 
Americas, Brazil, 1500, 330000 
Europe, Croatia, 500, 160000 
Americas, Mexico, 1800, 122000 
Americas, Argentina, 1200, 360000 
Europe, Portugal, 1100, 302500 
Europe, Spain, 800, 250000 
Europe, Denmark, 1500, 435000 
Europe, Belgium, 700, 154000 
Asia, China, 2000, 370000 
Asia, Japan...

Using Rank() with Aggr


The Rank() function is likely used to calculate the relative position of the value on the dimension of the chart, starting from 1 to N.

As Rank() requires a dimension in the object to calculate the relative position, how can we use it in a text object to show the name of the top five countries with more sales?

This recipe will show you how to use Rank() with Aggr to get this top five visualization in a dimensionless object.

Getting ready

For this recipe, we will reuse the data load for the Using nestedaggregations recipe of this chapter.

How to do it…

  1. Drag a Text & image object onto the content area.
  2. Add the following text: Top 5 Customers, and type Enter to create a new line.
  3. Format the text as bold.
  1. Go to the property editor and open the Data section.
  2. Add a new measure with the following expression:
=concat( 
    aggr( if (rank(sum(Sales)) <= 5, Country), Country)  ,  
    ',', 
    aggr(rank(sum(Sales)),Country) 
) 

The result will look like the following screenshot...

Combining set analysis with Aggr


This recipe will show you how to use set analysis with aggregation functions combined with Aggr().

Set analysis modifies the behavior of the filters in an aggregation expression. When using Aggr(), you have two aggregations, one inside Aggr() and the other outside Aggr(), as in the following example:

= Max( Aggr(rank(Sum(Sales)), Country)) 

Where to insert the set analysis expression? Will the result be the same?

This recipe will show how the set analysis in the inner or the outer aggregation affects the result.

Getting ready

For this recipe, we will reuse the data load for the Using nested aggregation recipe from ealier in this chapter.

How to do it…

  1. Drag a Table object.
  2. Add the text, Europe Rank, as the object title.
  3. Add a dimension: Country.
  4. Uncheck the Include null values property.
  5. Add a new measure with the following expression, with the Regional Rank label:
= Max( Aggr(rank(Sum( {<Region={'Europe'}>} Sales)), Country))
  1. Add the second measure with the following...

Creating an ABC analysis


ABC analysis divides a set of information, such as customers, products, suppliers, or any other dimension, into three categories: "A" for those contributing to the first 80% of an indicator, such as costs or sales, "B' for those contributing to the next 10%, and "C" for the final 10 %.

This recipe will show you how to create an ABC analysis coloring a dimension with this classification, and use the classification as a dimension, so you can filter only the countries that fall under the "B" category, for example.

Getting ready

For this recipe, we will reuse the data load for the Using nested aggregations recipe of this chapter.

How to do it…

  1. Create a new Dimension in the Master items library.
  2. In the dimension editor, select the expression editor for the field.
  3. Add the following expression:
=Aggr( 
    If(Rangesum(Above(Sum(Sales)/Sum(Total Sales),1,RowNo()))<0.8, 'A', 
     If(Rangesum(Above(Sum(Sales)/Sum(Total Sales),1,RowNo()))<0.9, 'B', 
      'C')), 
    (Country...
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Qlik Sense Cookbook. - Second Edition
Published in: Aug 2018Publisher: PacktISBN-13: 9781788997058
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (3)

author image
Pablo Labbe

Pablo is a Business Intelligence Consultant with over 18 years of experience. In 2008 he was presented to Qlikview, the former product by Qlik and the seed for Qlik Sense. Since that year he was focused on delivering BI solutions in a new way. Now he is the Principal of ANALITIKA Inteligencia delivering BI projects and training focusing on Qlik products and other technologies that embrace the Self-Service BI. He is an active member of the Qlik Community and other social media sites. You can follow him on Twitter - @pablolabbe and LinkedIn.
Read more about Pablo Labbe

author image
Philip Hand

Philip Hand is a Senior Business Intelligence consultant who has worked with QlikView in the BI space for over 7 years. Working with Qlik's top partner in the UK, he has implemented end-to-end solutions in a wide variety of enterprises and for large business customers. Philip has great experience and knowledge working across many sectors from the public sector, insurance, and financial services to large retailer and manufacturing businesses.
Read more about Philip Hand

author image
Neeraj Kharpate

Neeraj Kharpate works as a Senior Business Intelligence consultant at Capventis, a QlikView Elite Partner. Having started his career working as a technical support executive for an aviation ERP, Neeraj embarked on his journey with Qlikview in mid-2007. He is a certified Qlikview designer, developer, and trainer. Neeraj has been closely following the developments in Qlik Sense ever since it was launched in 2014 and is extremely excited about the future of this product. Neeraj has completed his Masters in Business Administration from the Norwich Business School, University of East Anglia. He also has a diploma in Management Consulting from the Chartered Management Institute, UK.
Read more about Neeraj Kharpate