Tutorial - Creating a set expression (2024)

You can build set expressions in Qlik Sense 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.

Videos

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.

Tutorial - Creating a set expression (1)

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:

  • Set modifiers

  • Set identifiers

  • Set operators

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

Do the following:

  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 using inline loads, see Using inline loads to load data.

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.

Do the following:

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

    Tutorial - Creating a set expression (2)
  2. Drag a KPI onto the sheet, and then click Add measure.

    Tutorial - Creating a set expression (3)
  3. Click Sales, and then select Sum(Sales) for the aggregation.

    Tutorial - Creating a set expression (4)

    The KPI shows the sum of sales for all years.

    Tutorial - Creating a set expression (5)
  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.

    Tutorial - Creating a set expression (6)

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

    Tutorial - Creating a set expression (7)
  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:

      Sum({<Year={2015}>}Sales)
      Tutorial - Creating a set expression (8)
    4. Click Apply to save the expression and to close the expression editor. The sum of Sales for 2015 is shown in the KPI.

      Tutorial - Creating a set expression (9)
  7. Create two more KPIs with the following expressions:

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

    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.

    Tutorial - Creating a set expression (10)

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.

Do the following:

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

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

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.

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

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.

Tutorial - Creating a set expression (11)

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.

Do the following:

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

Sum({$<Year={2015}>+1<Country={'Germany'}>}Sales)

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'}>.

Tutorial - Creating a set expression (12)

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.

Sum({$<Year={2015}>-1<Country={'Germany'}>}Sales)
Sum({$<Year={2015}>*1<Country={'Germany'}>}Sales)
Tutorial - Creating a set expression (13)

Set expression tutorial data

Load the following data as an inline load and then create the chart expressions in the tutorial.

For more information about using inline loads, see Using inline loads to load data.

//Create table SalesByCountrySalesByCountry:Load * Inline [Country, Year, SalesArgentina, 2016, 66295.03Argentina, 2015, 140037.89Austria, 2016, 54166.09Austria, 2015, 182739.87Belgium, 2016, 182766.87Belgium, 2015, 178042.33Brazil, 2016, 174492.67Brazil, 2015, 2104.22Canada, 2016, 101801.33Canada, 2015, 40288.25Denmark, 2016, 45273.25Denmark, 2015, 106938.41Finland, 2016, 107565.55Finland, 2015, 30583.44France, 2016, 115644.26France, 2015, 30696.98Germany, 2016, 8775.18Germany, 2015, 77185.68];
Tutorial - Creating a set expression (2024)

FAQs

What is a set analysis? ›

Set analysis offers a way of defining a set (or group) of data values that is different from the normal set defined by the current selections.

What is the introduction of set expressions? ›

Introduction. A set expression is an expression that when evaluated results in a set. It is a non-explicit way of defining a set, which contrasts with the explicit definition that we make when we assign values to a set in a data section, listing them one by one.

How do you express a set in math? ›

A set is often written by listing its elements between curly braces { }. For example, a set containing the numbers 1, 2, and 3 would be written as {1, 2, 3}.

How do you write basic expressions? ›

Writing simple expressions

Generally, you'll do this by replacing the words with operators that mean the same thing. So for instance, four divided by x could be 4 ÷ x.

What are set modifiers and set identifiers? ›

You can think of the Set Identifier as the 'starting point' for the data that is included in your Set Expression. This data set can be further modified using a Set Modifier. For example using the <[Month]={'Feb'}> modifier from the question. This sets the selection in the Month field to Feb.

What is value set analysis? ›

Value set analysis attempts to identify a tight over-approximation of the program state at any given point in the program and can be used to detect vulnerability.

What is the meaning of set of expression? ›

A phraseme, also called a set phrase, fixed expression, idiomatic phrase, multiword expression (in computational linguistics), or idiom, is a multi-word or multi-morphemic utterance whose components include at least one that is selectionally constrained or restricted by linguistic convention such that it is not freely ...

What comes first in an expression? ›

The order of operations are the rules that tell us the sequence in which we should solve an expression with multiple operations. The order is PEMDAS: Parentheses, Exponents, Multiplication, and Division (from left to right), Addition and Subtraction (from left to right).

What is the set analysis? ›

Set analysis predefines the SET OF DATA that our charts / tables use. So, using a Set Expression, we can tell our object (chart / table) to display values corresponding to various sets of data (e.g. a pre-defined time-period, geographic region, product lines etc.).

How do you use variables in set analysis? ›

Variables can also be used within set analysis. Simply replace part of the set analysis with the variable you want. It is recommended to use variables in set analysis in the modifiers. Not only can you use variables to replace values in set modifiers but you can also replace the whole set with variables.

What is a variable in an expression in qlik? ›

A variable in Qlik Sense is a named entity, containing a data value. When a variable is used in an expression, it is substituted by its value or the variable's definition. Example: The variable x contains the text string Sum(Sales).

How can a set be written? ›

In order to write set notation, use the curled brackets, {}, to indicate the elements of a set and a capital letter (usually) to indicate the set itself. Then, list the elements of the set within the brackets: A={1, 2, 3} for example.

How do I write set notation? ›

The simplest set notation used to represent the elements of a set is the curly brackets { }. An example of a set is A = {a, b, c, d}. Here the set is represented with a capital letter, and its elements are denoted by small letters. Set notation can be broadly classified as for set representation and for set operations.

How can we write set? ›

A set is represented by a capital letter symbol and the number of elements in the finite set is represented as the cardinal number of a set in a curly bracket {…}. For example, set A is a collection of all the natural numbers, such as A = {1,2,3,4,5,6,7,8,….. ∞}.

References

Top Articles
Latest Posts
Article information

Author: Horacio Brakus JD

Last Updated:

Views: 6127

Rating: 4 / 5 (51 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Horacio Brakus JD

Birthday: 1999-08-21

Address: Apt. 524 43384 Minnie Prairie, South Edda, MA 62804

Phone: +5931039998219

Job: Sales Strategist

Hobby: Sculling, Kitesurfing, Orienteering, Painting, Computer programming, Creative writing, Scuba diving

Introduction: My name is Horacio Brakus JD, I am a lively, splendid, jolly, vivacious, vast, cheerful, agreeable person who loves writing and wants to share my knowledge and understanding with you.