> ## Documentation Index
> Fetch the complete documentation index at: https://docs.activeviam.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Advanced scopes

> Reference for applying one limit to several members of a level in Atoti Limits. Covers the four advanced scope types (for each selected, for each excluding selected, total of selected, total excluding selected), their file notation, operators and restrictions, multi-level member scopes and simplified scope notation.

Advanced scopes apply one limit to several members of a level, for example several books, without creating one limit per member. An advanced scope is defined by two choices:

* **Which members the limit applies to.** These are the columns of the table below:
  * the listed members
  * all members except the listed ones
* **How the members are checked.** These are the rows of the table below:
  * each member separately against the limit
  * the members' combined value, once

Each combination is one advanced scope type, shown here with its label in the UI:

| | Listed members | All members except the listed ones |
| - | - | - |
| **Each member checked separately against the limit** | "(For each) selected" | "(For each) excluding selected" |
| **Combined value checked once against the limit** | "(Total) of selected" | "(Total) excluding selected" |

A combined value is shown at the `AllMember` level.

For example, a limit of 1,000,000 applies to Book 1 and Book 2, where Book 1 is 600,000 and Book 2 is 700,000:

* With "(For each) selected", each book is checked separately. 600,000 and 700,000 are both under the limit, so there is no breach.
* With "(Total) of selected", the combined 1,300,000 is checked once. It is over the limit, so there is a breach.

## What each scope type checks

### For each selected member

Each listed member is checked separately: the limit is evaluated where the level member is one of a set of supplied members. For example, a limit that applies to USD and EUR is checked for USD and for EUR separately.

Two "(For each) selected" limits on the same limit structure cannot cover the same member on the same dates. For example, if one limit covers USD and EUR from January to June, a second limit that covers EUR and GBP from March to December is rejected: both would apply to EUR from March to June.

### For each excluding selected member

Each member other than the listed ones is checked separately: the limit is evaluated where the level member is not one of a set of supplied members. For example, every currency except USD and EUR is checked separately.

Atoti Limits does not check whether two "(For each) excluding selected" limits on the same limit structure cover the same members. The `limits.scope.allow-multiple-not-in-limits` property can restrict a structure to one such limit at a time. See [limits.scope.allow-multiple-not-in-limits](https://docs.activeviam.com/atoti-intelligence/workflows/limits/6.2/dev/configure/scopes/scope-properties.md#limits-scope-allow-multiple-not-in-limits).

### Total of selected members

The combined value of the listed members is checked once: the limit is evaluated as the total of where the level member is one of a set of supplied members, and the value is displayed at the `AllMember` level. For example, the sum of the values of Book 1 and Book 2 is checked once.

> [!WARNING]
>
> A limit of this scope should not be used in conjunction with other limits or scope locations. For how Atoti Limits chooses between overlapping limits, see [Which limit applies when scopes overlap?](https://docs.activeviam.com/atoti-intelligence/workflows/limits/6.2/dev/configure/scopes/evaluation-priority.md).

> [!NOTE]
>
> The wildcard (`*`) and `AllMember` values are not allowed for this type of scope.

### Total excluding selected members

The combined value of all members other than the listed ones is checked once: the limit is evaluated as the total of locations where the level member is not one of a set of supplied members, and the value is displayed at the `AllMember` level. For example, the sum of the values of every book except Book 3 and Book 4 is checked once.

> [!WARNING]
>
> A limit of this scope should not be used in conjunction with other limits or scope locations. For how Atoti Limits chooses between overlapping limits, see [Which limit applies when scopes overlap?](https://docs.activeviam.com/atoti-intelligence/workflows/limits/6.2/dev/configure/scopes/evaluation-priority.md).

> [!NOTE]
>
> The wildcard (`*`) and `AllMember` values are not allowed for this type of scope.

## Write advanced scopes in a file

A scope can be written in two notations, and both can be mixed in the same file:

* **Simplified notation (recommended):** only the symbol and the members. Atoti Limits takes the level from the scope keys of the limit's limit structure, in the order they are listed. For the full notation, see [Simplified scopes](./scope-overview#example-notation-for-defining-simplified-scopes).
* **Verbose notation:** the level name, the symbol and the members. Each scope names its own level, so it does not depend on the order of the scope keys.

The symbol sets the scope type:

| Scope type | Symbol | Simplified | Verbose |
| - | - | - | - |
| [(For each) selected](#for-each-selected-member) | `=`, or no symbol | `[ USD + EUR ]` | `Currency = [ USD + EUR ]` |
| [(For each) excluding selected](#for-each-excluding-selected-member) | `<>` | `<> [ USD + EUR ]` | `Currency <> [ USD + EUR ]` |
| [(Total) of selected](#total-of-selected-members) | `&=` | `&= [ Book 1 + Book 2 ]` | `Book &= [ Book 1 + Book 2 ]` |
| [(Total) excluding selected](#total-excluding-selected-members) | `&<>` | `&<> [ Book 3 + Book 4 ]` | `Book &<> [ Book 3 + Book 4 ]` |

> [!NOTE]
>
> The `+` symbol here is merely for notational purposes and does not indicate addition of the members. We require distinct
> symbols to be used in order to correctly parse the scope on file import. For very complex scopes, we recommend using the UI rather than
> editing the file.

> [!NOTE]
>
> `<>` is the MDX representation of “[not equal to](https://learn.microsoft.com/en-us/sql/mdx/not-equal-to-mdx?view=sql-server-ver16)”.

Each location is pipe-separated, the level names are
[normalized](./scope-overview#scope-normalization) and missing parents of multi-level hierarchies are derived depending on user-defined
[scope properties](https://docs.activeviam.com/atoti-intelligence/workflows/limits/6.2/dev/configure/scopes/scope-properties.md).

> [!NOTE]
>
> Whitespaces between symbols will be trimmed.

### Special case: defining multiple multi-Level members

We may want to define a location on a multi-level hierarchy for multiple members. For example, we may want to evaluate at:

```
City = North America / United States / New York City
City = Europe / Ireland / Dublin
```

To do so, for this special case we use the following notation:

```
<Selected Level> <Operator> [ <Level Parent_0>=<Level Parent Value_0>&<Level Parent_1>=<Level Parent Value_1>&...&<Selected Level>=<Selected Value 1> +
                              <Level Parent_0>=<Level Parent Value_2>&<Level Parent_1>=<Level Parent Value_3>&...&<Selected Level>=<Selected Value 2> +
                              ...
                              <Level Parent_0>=<Level Parent Value_2>&<Level Parent_1>=<Level Parent Value_3>&...&<Selected Level>=<Selected Value n> +
                              ]
```

where:

* `Operator` is the symbol of the scope type, as listed in [Write advanced scopes in a file](#write-advanced-scopes-in-a-file).
* `Level Parent_n` is the level at ordinal `n` in the level path. This order is important and the topmost parent should be the first in the path.

In our city example above, this would look like:

```
City = [
        Continent@Geography=North America & Country=United States & City=New York City +
        Continent@Geography=Europe & Country=Ireland & City=Dublin
        ]
```

## Operator names in JSON payloads

In the `scopeType` field of JSON payloads, each scope type is named by its operator:

| Scope type | Operator |
| - | - |
| (For each) selected | `EQUALS` |
| (For each) excluding selected | `NOT EQUALS` |
| (Total) of selected | `TOTAL EQUALS` |
| (Total) excluding selected | `TOTAL EXCEPT` |
