Skip to main content

Design

The Design blog is all about product and Qlik solutions, such as scripting, data modeling, visual design, extensions, best practices, and more!

Announcements
Welcome to Qlik Community! Check out our new navigation! FIND OUT MORE
hic
Employee
Employee

In Set expressions, an equals sign can be used to assign a selection to a field. But this is not the only assignment symbol that can be used. There are a couple of others. This post is about the alternative assignments symbols that can be used, and their respective use cases.

Strictly speaking, the equals sign in set expressions is not an equals sign. Rather, it is an assignment symbol. This is the reason why you cannot use relational operators in its place. The equals sign assigns a selection state to a field e.g.

     { $ <Country = {Sweden, Germany, 'United States'}> }

In this case, the element set ‘Sweden’, ‘Germany’, ‘United States’ is assigned as selection to the field “Country”.

But what if the set identifier already has a selection in the field “Country”?

In such a case, the old selection will be replaced by the new one. It will be like first clearing the old selection of the field, then applying a new selection.

However, this is not the only way to assign a set as selection in a field. You can also use assignments with implicit set operators. These will use the existing selection in the field to define a new selection:

Implicit Union:

     { $ <Country += {'United States'}> }

Note the plus sign.

This expression will use the union between the existing selection and ‘United States’ as new selection in the field, i.e. add the listed values to the previously select ones. The use case is not a common one, but it happens sometimes that you always want to show a specific country (or product or customer) as a comparison to the existing selection. Then the implicit union can be used.

Implicit Intersection:

     { $ <Country *= {"=Continent='Europe' "}> }

Note the asterisk.

This will use the intersection between the existing selection of countries and the countries in Europe as new selection in the field. (The search is an expression search that picks out European countries.) The set expression will not remove any part of the existing condition – instead it will just be an additional limitation.

This construction can in many cases be used instead of a normal assignment. In fact, it is often a much better solution than the standard assignment, since it respects the user selection and thus is easier to understand.

The implicit intersection should be used more.

Implicit Exclusion:

     { $ <Country -= {'United States'}> }

Note the minus sign.

This expression will use the existing selection, but exclude ‘United States’. The use case for an implicit exclusion is exactly this – you want to exclude a value. Hence, this construction is very useful.

Implicit Symmetric Difference:

     { $ <Country /= {'United States'}> }

Note the slash.

The above expression will select values that belong either to existing selection, or to the values in the set expression, but not to both. It’s like an XOR. I have never used this, and I would like to challenge the readers to come up with a relevant use case.

Bottom line: Assignments with implicit set operators are sometimes very useful. You should definitely consider using the implicit intersection and the implicit exclusion.

HIC

Further reading related to this topic:

A Primer on Set Analysis

Why is it called Set Analysis?

13 Comments