# Set modifiers with set operators

Set operators are used to include, exclude, or intersect different element sets. They combine the different methods to define element sets.

The operators are the same as those used for set identifiers.

Operators

| Operator | Description |
| --- | --- |
| `+` | Union. This binary operation returns a set consisting of the records or elements that belong to any of the two set operands. |
| `-` | Exclusion. This binary operation returns a set consisting of the records or elements that belong to the first but not the other of the two set operands. Also, when used as a unary operator, it returns the complement set. |
| `*` | Intersection. This binary operation returns a set consisting of the records or elements that belong to both set operands. |
| `/` | Symmetric difference `(XOR)`. This binary operation returns a set consisting of the records or elements that belong to either, but not both set operands. |

For example, the following two modifiers define the same set of field values:

* `<Year = {1997, "20*"}>`

* `<Year = {1997} + {"20*"}>`

Both expressions select `1997` and the years that begin with `20`. In other words, this is the union of the two conditions.

Set operators also allow for more complex definitions. For example:

`<Year = {1997, "20*"} - {2000}>`

This expression will select the same years as those above, but in addition exclude year `2000`.

For more information, see [Set operators](https://help.qlik.com/en-US/sense/May2025/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/SetAnalysis/set-operators.htm).

## Examples: Chart expressions for set modifiers with set operators

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/SetAnalysis/set-modifiers-set-operators.htm)

#### Examples - chart expressions

Load script

Load the following data as an inline load in the data load editor to create the chart expression examples below.

```
MyTable:
Load 
Year(Date) as Year,
Date#(Date,'YYYY-MM-DD') as ISO_Date, 
Date(Date#(Date,'YYYY-MM-DD'),'M/D/YYYY') as US_Date, 
Country, Product, Amount 
Inline
[Date, Country, Product, Amount
2018-02-20, Canada, Washer, 6
2018-07-08, Germany, Anchor bolt, 10
2018-07-14, Germany, Anchor bolt, 3
2018-08-31, France, Nut, 2
2018-09-02, Czech Republic, Bolt, 1
2019-02-11, Czech Republic, Bolt, 3
2019-07-31, Czech Republic, Washer, 6
2020-03-13, France, Anchor bolt, 1
2020-07-12, Canada, Anchor bolt, 8
2020-09-16, France, Washer, 1];	
```

For more information about using inline loads, see [Using inline loads to load data](https://help.qlik.com/en-US/sense/May2025/Subsystems/Hub/Content/Sense_Hub/Scripting/inline-loads-qs.htm).

Chart expressions

Create a table in a Qlik Sense sheet with the following chart expressions.

Table - Set modifiers with set operators

| Country | Sum(Amount) | Sum({&lt;Year={"&gt;2018"}-{2020}&gt;} Amount) | Sum({&lt;Country=-{Germany}&gt;} Amount) | Sum({&lt;Country={Germany}+P({&lt;Product={Nut}&gt;}Country)&gt;} Amount) |
| --- | --- | --- | --- | --- |
| Totals | 41 | 9 | 28 | 17 |
| Canada | 14 | 0 | 14 | 0 |
| Czech Republic | 10 | 9 | 10 | 0 |
| France | 4 | 0 | 4 | 4 |
| Germany | 13 | 0 | 0 | 13 |

Explanation

* Dimensions:

  * `Country`

* Measures:

  * `Sum(Amount)`

    Sum `Amount` with no set expression.

  * `Sum({<Year={">2018"}-{2020}>}Amount)`

    Sum `Amount` for all years after `2018`, except `2020`.

  * `Sum({<Country=-{Germany}>}Amount)`

    Sum `Amount` for all countries except `Germany`. Note the unary exclusion operator.

  * `Sum({<Country={Germany}+P({<Product={Nut}>}Country)>}Amount)`

    Sum `Amount` for `Germany` and all countries associated with the product `Nut`.

Set modifiers with set operators

Set modifiers with set operators

Set modifiers with set operators ![Set modifiers with set operators.](https://help.qlik.com/en-US/sense/May2025/Subsystems/Hub/Content/Resources/Images/ui_gen_setanalysis_set_operators.png)

For more information about expressions, see [Using expressions in visualizations](https://help.qlik.com/en-US/sense/May2025/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/use-expressions-in-visualizations.htm).

| Examples | Results |
| --- | --- |
| sum( {$&lt;Product = Product + {OurProduct1} – {OurProduct2} &gt;} Sales ) | Returns the sales for the current selection, but with the product “OurProduct1” added to the list of selected products and “OurProduct2” removed from the list of selected products. |
| sum( {$&lt;Year = Year + ({“20\*”,1997} – {2000}) &gt;} Sales ) | Returns the sales for the current selection but with additional selections in the field “Year”: 1997 and all that begin with “20” – however, not 2000.<br><br>Note that if 2000 is included in the current selection, it will still be included after the modification. |
| sum( {$&lt;Year = (Year + {“20\*”,1997}) – {2000} &gt;} Sales ) | Returns almost the same as above, but here 2000 will be excluded, also if it initially is included in the current selection. The example shows the importance of sometimes using brackets to define an order of precedence. |
| sum( {$&lt;Year = {“\*”} – {2000}, Product = {“\*bearing\*”} &gt;} Sales ) | Returns the sales for the current selection but with a new selection in “Year”: all years except 2000; and only for products containing the string 'bearing'. |