Вы находитесь на странице: 1из 12

# SET ANALYSIS

A BEGINNERS GUIDE

Version: 2.0
Date: 2013-10-29
Author(s) FIM

CONTENTS
Contents .................................................................................................................................. 2
Introduction ............................................................................................................................. 3
Basic Syntax ........................................................................................................................... 4
Examples .............................................................................................................................. 5
Dynamic Record Sets ............................................................................................................. 7
Adding and Removing Values to Selections ....................................................................... 9
More Examples ..................................................................................................................... 11

Page | 3

INTRODUCTION
Qlikview Green/White/Grey functionality is a very simple and intuitive concept. A user
makes a series of selections and narrows the applications data set and associated
charts/reports. Set Analysis is Qlikview function that allows you to override this
functionality and take control of the selections at an object or chart level. Set Analysis
gives the developer complete control over which data is reported in the chart.
The following are some scenarios where a developer may wish to use Set Analysis:-
To compare a measure for multiple time periods.
To restrict values from fields in a calculation
To Ignore or include some or all of the current selections
To perform Cumulative calculations or Year to date results.
It is a very simple concept although the syntax can appear complicated.

Page | 4

BASIC SYNTAX
The following example is used to show how a Set Analysis is composed; Sum of Sales for
the country UK to include all current selections.
The field to be used in the expression is SALES and the values in that field are to be
added together therefore Sum is used. The starting point (IN BLACK) is:-
Sum(SALES)
The Set portion of the expression is then added immediately after the first parenthesis
and is enclosed in curly brackets {set expression}
Immediately after the first curly bracket ({) a \$ sign states that the record set will honor
existing current selections and a 1 states that all current selections are to be ignored and
the set analysis is to be based on a full data set. Since the example requires current
selections to be included a \$ is used(IN RED):-
Sum ({\$}Sales)
Next the field/s that will be used in the set expression are defined and these are added
immediately after the \$ and enclosed in less than / greater than (<>) symbols(IN
GREEN). In this example only records where country equals UK are to be included, the
completed Set Analysis statement is:-
Sum ({\$ <Country ={UK} > } Sales)
Or it can help, when reading a Set Statement to separate the syntax across multiple
lines:-
Sum (
{\$
<Country = {UK} >
}
Sales)

Page | 5

EXAMPLES

Standard Sum of field Sales:-

SUM( SALES)

Set Analysis style SUM of field Sales. The \$ means that all current selections remain:-

SUM(
{\$}
SALES)

Set style SUM of field Sales. The 1 means current selections are ignored:-
SUM(
{1}
SALES)

SUM of Sales for All(*) countries and including current selections:-
SUM(
{\$
<[Country] = {"*"} >
}
SALES)

Sum of Sales for all counties, excluding current selections:-
SUM(
{1
<[Country] = {"*"} >
}
SALES)

Sum of Sales for United Kingdom and including current selections:-
SUM(
{\$
<[Country] = {"UK"} >
}
SALES)

Page | 6

Sum of Sales for All Countries except United Kingdom, including current selections:-
SUM(
{\$
<[Country] -= {"UK"} >
}
SALES)

Page | 7

DYNAMIC RECORD SETS

Point in Time reporting is easily achieved using set analysis. If you wanted to obtain the
years sales for 2010 the following set analysis would be used:-

Sum(
{\$
<Year = {2010}>
}
Sales)

If you wanted to return Sales for the immediate previous year to whatever the user
selects, you can use the aggregation function:-

First determine the function that will return the required value, Max(Year) 1. In this
example if the user selects 2010, the function will return 2009, if the user makes multiple
selections or no selections at all, you will still get the value of the previous year based on
the last possible year.

Next you use this function as a set modifier in the final expression, as follows:-

\$(=Function()) (NB equal sign)

The final expression would look as follows:-

Sum(
{\$
<Year = {\$(=Max(Year) 1))
}
Sales

Page | 8

This approach works equally well for Quarters, Months, Days etc. however its limitation is
demonstrated when working with months for example, if a user selects Month 1 (January)
and uses the function Max(Month) a zero will be returned and this is not what is required.

Page | 9

ADDING AND REMOVING VALUES TO SELECTIONS
The following operators can be used to modify the selections that have been made by the
user:-

= Redefines the selection made for a given field

+= Defines a union between the selected field value and the next specified:-
Sum(
{\$
<Year += {2009, 2010}>
}
Sales)
This expression will return the sales for the years that the user has selected AND
the years 2009 and 2010.

-= Defines an exclusion of the value specified from the value that the user
has selected:-
Sum(
{\$
<Product -= {Product X}>
}
Sales)
This expression will return the sales for the products the user has selected
excluding Product X.

*= Defines the values that occur in both the users selections and the values
specified in the set expression:-
Sum(
{\$

Page | 10

<Product *= {Product X}>
}
Sales)
returns the sales for the current selection but only for the intersection of currently
selected products and Product X.

/= This defines an XOR, the resulting record set will contain the values
present in either one set but not in the other:-
Sum(
{\$
<ProductNumber *= {33*}>
}
Sales)
. Returns the sales for the current selection but only for the intersection of currently
selected products and all the products with numbers starting with 33

Page | 11

MORE EXAMPLES

Sum of Sales and ignore specific selections for Customer Country and Policy Status:-
SUM( {\$<[Customer Country] = , [Policy Status] = >} Sales )

Sum of Sales where Policy Created Year equals variable vMaxCreatedYear:-
SUM( {\$<[Policy Created Year] = {\$(#vMaxCreatedYear)}>} Sales )

Sum of Sales where Policy Created Year greater than or equal to variable v2002:-
SUM( {\$<[Policy Created Year] = {">=\$(#v2002)"}>} Sales )

Sum of Sales where Policy Created Year less than variable v2002:-
SUM( {\$<[Policy Created Year] = {"<\$(#v2002)"}>} Sales )

Sum of Sales where Policy Created Year greater than or equal to v2002 and less than or equal to
v2004:-
SUM( {\$<[Policy Created Year] = {">=\$(#v2002) <=\$(#v2004)"} >} Sales )

Sum of Sales where Product not equal to Life Plan:-
SUM( {\$<Product -= {"Life Plan"} >} Sales )

Sum of Sales where Policy Created Year is greater than 1999 but less than 2004:-
SUM( {\$<[Policy Created Year] = {>1999<2004}>} Sales )

Sum of Sales for policies created in the Years beginning 200* :-
SUM( {\$<[Policy Created Year] = {200*}>} Sales )

Sum of Sales excluding where Product equals *Plan* :-
SUM( {\$<~Product = {*Plan*}>} Sales )

Sum of Sales to include all current selections and the union of the 2 products, Life Plan
and Fleet Secure:-
SUM( {\$<Product += {"Life Plan", "Fleet Secure"} >} Sales )

Sum of Sales to include all current selections and Years 20* and 1997 minus the year
2000:-
SUM( {\$<[Policy Created Year] += {20*,1997} {2000} >} Sales )

Page | 12

Sum of Sales to include all current selections, and the intersect of product Fleet Secure:-

SUM( {\$<Product *= {"Fleet Secure"} >} Sales )

This expression returns the sum of sales for the previous year in relation to the current
selection. A dollar-sign expansion is used to calculate the previous year:-
SUM( {\$<[Policy Created Year] = {\$(#=Only([Policy Created Year])-1)}>} Sales )

Returns the sum of Sales for all current selections excluding the products with Plan and
Secure in their title:-
SUM({\$-1<Product = {"*Plan*", "*Secure*"}>} Sales )

Return the sum of sales for all current selections, with a new selection in the Customer
field. Only include customers who during 2007 had total sales of more than 1000000:-
SUM(
{\$
<Customer = {=Sum({1<Year = {2007}>} Sales ) > 1000000}>
}
Sales )