You are on page 1of 1

Set analysis cheat Sheet

ANATOMY OF A SET EXPRESSION To build set expressions, we must


first get the syntax right.
Understand the various elements
that make up a set expression and
what characters are used to enclose
each of them.

{ } - Used to enclose the entire set


expression, and also to enclose the
element list.

$ or 1 - Common values used as


the set identifier. (See below)

< > - Used to enclose a set


modifier.

BASIC CONCEPTS OPERATORS


 Set identifier: is used to define the There are two types of operators: Both types of operators work similarly,
starting point in the definition of a) Assignment Operators: to and the only difference is that
the alternative record set that will determine how to combine the field assignment operators carry an equal
be used in the final expression. values with an element list. (=) sign as suffix, while their set
 Set modifier: is the set of b) Set Operators: to work with several operator counterparts do not.
field-value definitions with which element lists or several set modifiers.
we modify the initial record set. Notes:
Use the following diagrams to
This can also be thought of as the In the following diagrams, A and B represent understand the result of each operator.
set of filters that we want to apply set modifiers, elements lists or the fields
on the record set. initial record set, depending on the context.
 Element list: is a list of values we RE-ASSIGNMENT
Included in the
use to filter the record set on a
given field. An element list is tied
final record set. = Redefines the selection
for a certain field. This is
to a specific field. Not included in only used as assignment
the final record set. A
operator and there is no
equivalent set operator.
SET IDENTIFIERS UNION
eg: Field = {A}
The following set identifiers are the + Implicitly defines a union
most commonly used: between a fields inital record set and
the element list, between two element EXCLUSION
- Implicitly defines an exclusion
$ when the alternative record set lists or between two set modifiers.
should be initially based on the
between a fields inital record set and
current user selections.
the element list, between two element
1 when the alternative record set A B lists or between two set modifiers.
should be initially based on the
full record set (all the data
contained in the QlikView
eg: Field += {A} A B
document), ignoring all user
selections. eg: {A} + {B}
eg: <A> + <B>
BM01 (the ID of a bookmark) to use eg: Field -= {A}
the selection state stored in a
eg: {A} - {B}
bookmark as basis for the INTERSECTION
alternative record set. eg: <A> - <B>
* Used to define the alternative
record set based on the intersection
between a fields initial record set and SYMMETRIC DIFFERENCE
ELEMENT LISTS an element list, between two element
/ Used to define a symmetric
lists, or between two set modifiers.
 Text elements are enclosed in difference (XOR). The modified record
straight single quotes. set will contain the values that are
eg: present in either one set, but not in
<Region = {'North'}> A B both.

 We can use search strings enclosed


in straight double quotes. A B
eg: eg: Field *= {A}
<Age = {">=18"}>
eg: {A} * {B}
 Numeric values in the element list eg: <A> * <B> eg: Field /= {A}
do not require quotes. eg: {A} / {B}
eg: eg: <A> / <B>
<Year = {2013}>

PRO TIPS
QLIKVIEW COMPONENTS SCRIPTING LIBRARY ELEMENT FUNCTIONS
Using set analysis for period-over-period comparisons (point in There are two special functions that can be used in set
time reporting) has never been easier. With the QlikView expressions to implicitly specify an element list. The functions
Components scripting library, you can generate set variables are:
automatically and use them in your expressions right away.  P() - to use all possible values in a field (as dictated by the
current selection state) as the element list.
One line of code to create both a master calendar table and the  E() - to use all excluded values in a field (as dictated by the
related set variables. current selection state) as the element list.
CALL Qvc.CalendarFromField('OrderDate');
A quick example:
Then, on the expression, you can get, for instance, the previous Sum({1<Year = p(Year)>} Sales)
years month to date sales with:
Sum($(vSetPreviousYearMTD) Sales) This expression will use the full set of data disregarding all user
selections (using 1 as the set identifier), but take into account
Visit www.qlikviewcomponents.org to learn more. those records corresponding to the years that the user has
selected. In other words, only selections made on the Year field
are considered.

RESOURCES ABOUT
To learn more about the power of Set Analysis: This material was created by Miguel Ángel García, co-author of
 Memorize this Cheat Sheet! the book QlikView 11 for Developers.
 Visit the series of blog posts titled “The Magic of Set Analysis”
at the AfterSync blog (http://blog.aftersync.com). Checkout more resources like this at
 Get your hands on the QlikView 11 for Developers book, https://aftersync.com/blog
authored by Miguel Ángel García and Barry Harmsen.
 Get your hands dirty and start experimenting!

www.aftersync.com

You might also like