QYB - Set Analysis and AGGR Exercises
QYB - Set Analysis and AGGR Exercises
Advanced Aggregation
Hands-On Exercises
Authorized translation excerpted from the English language edition QlikView Your Business:
An Expert Guide to Business Discovery with QlikView and Qlik Sense.
Copyright 2015 by John Wiley & Sons, Inc.
All Rights Reserved. This translation published under license with the original publisher John
Wiley & Sons, Inc.
Exercise 1: Bucket Analysis
1. Open the sheet named 1. Buckets.
2. Create a Bar Chart.
3. Create a Calculated Dimension and add the formula that calculates the Bucket based on
the Profit Margin, for each Customer (explained below).
4. Use the following formula for the calculation of the Profit Margin:
sum(
AGGR(
IF( (sum([# Amount]) - sum([# COGS])) / sum([# Amount]) >0.25, 1, 0)
, Product)
)
3.3. Use similar formulas (adjust the conditions conditions) for Black and Red colors.
4. Clone the summarized chart and change the Dimension to Channel.
4.1. The calculation by Channel requires adding the Channel field to the list of AGGR
dimensions:
sum(
AGGR(
IF( (sum([# Amount]) - sum([# COGS])) / sum([# Amount]) >0.25, 1, 0)
, Product, Channel)
)
max(
AGGR(
sum([# Amount]),
Salesperson, MonthYear)
)
3. For Best Sales Month, use FirstSortedValue() for the field MonthYear, sorted by the same
AGGR() function of aggregated Sales by Salesperson and MonthYear. Multiply by -1 to sort
in the descending order:
FirstSortedValue( MonthYear,
-AGGR(sum([# Amount]), Salesperson, MonthYear)
)
4. For Most Profitable Customer, build a similar FirstSortedValue() expression for the field
Customer, sorted by the AGGR() function of aggregated Profit Margins by Salesperson and
Customer:
FirstSortedValue( Customer,
-AGGR((sum([# Amount]) - sum([# COGS]) - sum([# CM Amount]))
/ sum([# Amount])
, Salesperson, Customer)
)
5. Create a Straight Table that shows the Number of Pareto Customers by Channel:
5.1. Use Channel as a Dimension
5.2. Create an Expression for the Number of Pareto Customers:
count({$<Customer=>} distinct
AGGR({$<Customer=>}
if(rangesum(Above(sum([# Amount])/sum( total <Channel> [# Amount]) , 0,
RowNo())) <= 0.8, Customer)
, Channel
, (Customer, (=sum([# Amount]), DESC))
)
)
6. Clone the Straight Table and transform it to show the Number of Pareto Customers by
Brand:
6.1. Use Brand as a Dimension
6.2. Replace Channel in the list of AGGR dimensions by Brand:
count({$<Customer=>} distinct
AGGR({$<Customer=>}
if(rangesum(Above(sum( [# Amount])/sum(total <Brand> [# Amount]) , 0,
RowNo())) <= 0.8, Customer)
, Brand
, (Customer, (=sum( [# Amount]), DESC))
)
)