Download - Set Analysis Beginners Guide v2.0[1]
-
8/12/2019 Set Analysis Beginners Guide v2.0[1]
1/12
SET ANALYSIS
A BEGINNERS GUIDE
Version: 2.0
Date: 2013-10-29
Author(s) FIM
-
8/12/2019 Set Analysis Beginners Guide v2.0[1]
2/12
CONTENTS
Contents .................................................................................................................................. 2
Introduction ............................................................................................................................. 3
Basic Syntax ........................................................................................................................... 4
Examples .............................................................................................................................. 5
Dynamic Record Sets ............................................................................................................. 7
Adding and Removing Values to Selections ....................................................................... 9
More Examples ..................................................................................................................... 11
-
8/12/2019 Set Analysis Beginners Guide v2.0[1]
3/12
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 Analysisgives 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.
-
8/12/2019 Set Analysis Beginners Guide v2.0[1]
4/12
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 currentselections 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 ({$ }Sales)
Or it can help, when reading a Set Statement to separate the syntax across multiple
lines:-
Sum (
{$
}
Sales)
-
8/12/2019 Set Analysis Beginners Guide v2.0[1]
5/12
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({$}SALES)
Sum of Sales for all counties, excluding current selections:-SUM({1}SALES)
Sum of Sales for United Kingdom and including current selections:-
SUM(
{$
}
SALES)
-
8/12/2019 Set Analysis Beginners Guide v2.0[1]
6/12
Page | 6
Sum of Sales for All Countries except United Kingdom, including current selections:-
SUM(
{$
}
SALES)
-
8/12/2019 Set Analysis Beginners Guide v2.0[1]
7/12
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(
{$
}
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(
{$
-
8/12/2019 Set Analysis Beginners Guide v2.0[1]
8/12
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.
-
8/12/2019 Set Analysis Beginners Guide v2.0[1]
9/12
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(
{$
}
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(
{$
}
Sales)
This expression will return the sales for the products the user has selected
excludingProduct X.
*= Defines the values that occur in both the users selections and the values
specified in the set expression:-
Sum(
{$
-
8/12/2019 Set Analysis Beginners Guide v2.0[1]
10/12
Page | 10
}
Sales)
returns the sales for the current selection but only for the intersection of currentlyselected 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(
{$
}
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
-
8/12/2019 Set Analysis Beginners Guide v2.0[1]
11/12
Page | 11
MORE EXAMPLES
Sum of Sales and ignore specific selections for Customer Country and Policy Status:-
SUM({$}Sales )
Sum of Sales where Policy Created Year equals variable vMaxCreatedYear:-SUM( {$}Sales )
Sum of Sales where Policy Created Year greater than or equal to variable v2002:-SUM( {$}Sales )
Sum of Sales where Policy Created Year less than variable v2002:-SUM( {$}Sales )
Sum of Sales where Policy Created Year greater than or equal to v2002 and less than or equal tov2004:-SUM( {$}Sales )
Sum of Sales where Product not equal to Life Plan:-SUM( {$} Sales )
Sum of Sales where Policy Created Year is greater than 1999 but less than 2004:-SUM( {$1999} Sales )
Sum of Sales for policies created in the Years beginning 200* :-SUM( {$}Sales )
Sum of Sales excluding where Product equals *Plan* :-SUM( {$} Sales )
Sum of Sales to include all current selections and the union of the 2 products, Life Plan
and Fleet Secure:-
SUM( {$}Sales )
Sum of Sales to include all current selections and Years 20* and 1997 minus the year
2000:-
SUM( {$}Sales )
-
8/12/2019 Set Analysis Beginners Guide v2.0[1]
12/12
Page | 12
Sum of Sales to include all current selections, and the intersect of product Fleet Secure:-
SUM( {$}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( {$}Sales )
Returns the sum of Sales for all current selections excluding the products with Plan and
Secure in their title:-
SUM({$-1}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(
{$
1000000}>
}
Sales )