OLAP Aggregate Queries : Grouping Parameter : Special Grouping Functions : INCLUDE and EXCLUDE Functions

INCLUDE and EXCLUDE Functions
In an aggregate query, normally all values of a scalar grouping field are used to create groups. For example:
GET /Email/Message/_aggregate?f=Tags&...
All values of the Tags field for selected objects are used to create grouping fields. To eliminate specific values from being used for grouping—without affecting the selection of the owning object—the EXCLUDE function can be used:
GET /Email/Message/_aggregate?f=Tags.EXCLUDE('Confidential, 'Internal')&...
When the grouping field is a text field, the values passed to the EXCLUDE function are whole, case-insensitive values—not terms—and must be enclosed in quotes. In the example above, groups matching the value Confidential or Internal or case variations of these are excluded. The values used for text scalars can contain wildcards ? and *. For example:
GET /Email/Message/_aggregate?f=Tags.EXCLUDE('*sam?')&...
This aggregate query excludes all groups that end with the samx, where x is any letter, or case variations of this sequence.
To generate only groups that match specific scalar values—without affecting the selection of the owning object—the INCLUDE function can be used:
GET /Email/Message/_aggregate?f=Tags.INCLUDE('Confidential, 'Internal')&...
The only groups generated are those matching Confidential and Internal and case variations of these; all other values are skipped. Again, when the grouping field is a text scalar, the value must be enclosed in quotes, and it can contain wildcards ? and *.
The values passed to INCLUDE and EXCLUDE must be compatible with the corresponding scalar type field: integers for integer or long fields, Booleans for boolean fields, etc. Additionally, the keyword NULL (uppercase) can be used to include or exclude the (null) group normally generated when at least one object has a null value for the grouping field. Example:
GET /Email/Message/_aggregate?f=Tags.EXCLUDE(NULL)&...
INCLUDE and EXCLUDE can be used in the same grouping expression. Because the functions are processed in order from left-to-right, it is most useful to use INCLUDE first, to select a overly-broad set of values, and then use EXCLUDE to prune-out unwanted values. INCLUDE and EXCLUDE can also be used in conjunction with other grouping functions, as shown in this example:
GET /Email/Person/_aggregate?m=COUNT(*)&f=TOP(10,Name.INCLUDE(aaron*).EXCLUDE(*Murphy))&range=0
This query returns a COUNT of the TOP 10 most-used Name values, but it only INCLUDEs names that begin with “aaron”. Within those names, it EXCLUDEs names that end with “murphy”.