Skip to main content Skip to complementary content

Tutorial - Creating a set expression

You can build set expressions to support data analysis. In this context, the analysis is often referred to as set analysis. Set analysis offers a way of defining a scope that is different from the set of records defined by the current selection in an app.

What you will learn

This tutorial provides the data and chart expressions to build set expressions using set modifiers, identifiers and operators.

Who should complete this tutorial

This tutorial is for app developers who are comfortable working with the script editor and chart expressions.

What you need to do before you start

A Qlik Sense Enterprise professional access allocation, which allows you to load data and create apps.

Further reading and resources

  • The Set analysis topics in the help provide an overview of set analysis, detailed description of the set expression elements, and examples.

  • Qlik offers a wide variety of resources when you want to learn more.
  • Training, including free online courses, is available in the Qlik Continuous Classroom.
  • Discussion forums, blogs, and more can be found in Qlik Community.


The following videos complement this tutorial.

The first video shows basic set expressions that are similar to those that are described in this tutorial. The second video demonstrates more complex set expressions.

Elements in a set expression

Set expressions are enclosed in an aggregation function, such as Sum(), Max(), Min(), Avg(), or Count(). Set expressions are constructed from building blocks known as elements. These elements are set modifiers, identifiers, and operators.

Elements in a set expression

Elements in a set expression.

The set expression above, for example, is built from the aggregation Sum(Sales). The set expression is enclosed in the outer curly brackets: { }

The first operand in the expression is: $<Year={2021}>

This operand returns sales for the year 2021 for the current selection. The modifier, <Year={2021}>, contains the selection of the year 2021. The $ set identifier indicates that the set expression is based on current selection.

The second operand in the expression is: 1<Country={'Sweden'}>

This operand returns Sales for Sweden. The modifier, <Country={'Sweden'}>, contains the selection of the country Sweden. The 1 set identifier indicates that selections made in the app will be ignored.

Finally, the + set operator indicates that the expression returns a set consisting of the records that belongs to any of the two set operands.

For more information, see:

Creating a set expression tutorial

Complete the following procedures to create the set expressions shown in this tutorial.

Create a new app and load data

  1. Create a new app.
  2. Click Script editor. Alternatively, click Prepare > Data load editor in the navigation bar.
  3. Create a new section in the Data load editor.
  4. Copy the following data and paste it into the new section: Set expression tutorial data
  5. Click Load data. The data is loaded as an inline load.

For more information about inline loads, see: Inline loads

Create set expressions with modifiers

The set modifier consists of one or more field names, each followed by a selection that should be made on the field. The modifier is enclosed by angled brackets. For example, in this set expression:

Sum ( {<Year = {2015}>} Sales )

The modifier is:

<Year = {2015}>

This modifier specifies that data from the year 2015 will be selected. The curly brackets in which the modifier is enclosed indicate a set expression.

  1. In a sheet, open the Assets panel from the navigation bar, and then click Charts.

    KPIs using set modifiers.
  2. Drag a KPI onto the sheet, and then click Add measure.

    KPIs using set modifiers.
  3. Click Sales, and then select Sum(Sales) for the aggregation.

    KPIs using set modifiers.

    The KPI shows the sum of sales for all years.

    KPIs using set modifiers.
  4. Copy and paste the KPI to create a new KPI.

  5. Click the new KPI, click Sales under Measures, and then click Open Expression editor.

    KPIs using set modifiers.

    The expression editor open with the aggregation Sum(Sales).

    KPIs using set modifiers.
  6. In the expression editor, create an expression to sum Sales for 2015 only: 

    1. Add curly brackets to indicate a set expression: Sum({}Sales)
    2. Add angle brackets to indicate a set modifier: Sum({<>}Sales)

    3. In the angle brackets, add the field to be selected, in this case the field is Year, followed by an equal sign. Next, enclose 2015 in another set of curly brackets. The resulting set modifier is: {<Year={2015}>}.

      The entire expression is:

      KPIs using set modifiers.
    4. Click Apply to save the expression and to close the expression editor. The sum of Sales for 2015 is shown in the KPI.

      KPIs using set modifiers.
  7. Create two more KPIs with the following expressions:


    The modifier in the above is <Year={2015,2016}>. The expression will return the sum of Sales for 2015 and 2016.

    Sum({<Year={2015},Country={'Germany'}>} Sales)

    The modifier in the above is <Year={2015}, Country={'Germany'}>. The expression will return the sum of Sales for 2015, where 2015 intersects with Germany.

    KPIs using set modifiers

    KPIs using set modifiers.

Add set identifiers

The set expressions above will use current selections as base, because an identifier was not used. Next, add identifiers to specify the behavior when selections are made.

On your sheet, build or copy the following set expressions:


The $ identifier will base the set expression on the current selections made in the data. This is also the default behavior when an identifier is not used.


The 1 identifier will cause the aggregation of Sum(Sales) on 2015 to ignore the current selection. The value of the aggregation will not change when the user makes other selections. For example, when Germany is selected below, the value for the aggregate sum of 2015 does not change.

KPIs using set modifiers and identifiers

KPIs using set modifiers and identifiers.

Add operators

Set operators are used to include, exclude, or intersect data sets. All operators use sets as operands and return a set as result.

You can use set operators in two different situations:

  • To perform a set operation on set identifiers, representing sets of records in data.

  • To perform a set operation on the element sets, on the field values, or inside a set modifier.

On your sheet, build or copy the following set expression:


The plus sign (+) operator produces a union of the data sets for 2015 and Germany. As explained with set identifiers above, the dollar sign ($) identifier means current selections will be used for the first operand, <Year={2015}>, will be respected. The 1 identifier means selection will be ignored for the second operand, <Country={'Germany'}>.

KPI using plus sign (+) operator

KPIs using set modifiers and identifiers.

Alternatively, use a minus sign (-) to return a data set that consists of the records that belong to 2015 but not Germany. Or, use an asterisk (*) to return a set consisting of the records that belong to both sets.



KPIs using operators

KPIs using set modifiers and identifiers.

Set expression tutorial data

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!