Skip to main content Skip to complementary content

Aggr - chart function

Aggr() returns an array of values for the expression calculated over the stated dimension or dimensions. For example, the maximum value of sales, per customer, per region.

The Aggr function is used for nested aggregations, in which its first parameter (the inner aggregation) is calculated once per dimensional value. The dimensions are specified in the second parameter (and subsequent parameters).

In addition, the Aggr function should be enclosed in an outer aggregation function, using the array of results from the Aggr function as input to the aggregation in which it is nested.

Syntax:  

Aggr({SetExpression}[DISTINCT] [NODISTINCT ] expr, StructuredParameter{, StructuredParameter})

Return data type: dual

Arguments:  

Arguments
Argument Description
expr

An expression consisting of an aggregation function. By default, the aggregation function will aggregate over the set of possible records defined by the selection.

StructuredParameter

StructuredParameter consists of a dimension and optionally, sorting criteria in the format: (Dimension(Sort-type, Ordering))

The dimension is a single field and cannot be an expression. The dimension is used to determine the array of values the Aggr expression is calculated for.

If sorting criteria are included, the array of values created by the Aggr function, calculated for the dimension, is sorted. This is important when the sort order affects the result of the expression the Aggr function is enclosed in.

For details of how to use sorting criteria, see Adding sorting criteria to the dimension in the structured parameter.

SetExpression By default, the aggregation function will aggregate over the set of possible records defined by the selection. An alternative set of records can be defined by a set analysis expression.
DISTINCT

If the expression argument is preceded by the distinct qualifier or if no qualifier is used at all, each distinct combination of dimension values will generate only one return value. This is the normal way aggregations are made – each distinct combination of dimension values will render one line in the chart.

NODISTINCT

If the expression argument is preceded by the nodistinct qualifier, each combination of dimension values may generate more than one return value, depending on underlying data structure. If there is only one dimension, the aggr function will return an array with the same number of elements as there are rows in the source data.

Basic aggregation functions, such as Sum, Min, and Avg, return a single numerical value, whereas the Aggr() function can be compared to creating a temporary staged result set (a virtual table), over which another aggregation can be made. For example, by computing an average sales value by summing the sales by customer in an Aggr() statement, and then calculating the average of the summed results: Avg(TOTAL Aggr(Sum(Sales),Customer)).

Tip noteUse the Aggr() function in calculated dimensions if you want to create nested chart aggregations on multiple levels.

Limitations:  

Each dimension in an Aggr() function must be a single field, and cannot be an expression (calculated dimension).

In its basic form, the argument StructuredParameter in the Aggr function syntax is a single dimension. The expression: Aggr(Sum(Sales, Month)) finds the total value of sales for each month. However, when enclosed in another aggregation function, there can be unexpected results unless sorting criteria are used. This is because some dimensions can be sorted numerically or alphabetically, and so on.

In the StructuredParameter argument in the Aggr function, you can specify sorting criteria on the dimension in your expression. This way, you impose a sort order on the virtual table that is produced by the Aggr function.

The argument StructuredParameter has the following syntax:

(FieldName, (Sort-type, Ordering))

Structured parameters can be nested:

(FieldName, (FieldName2, (Sort-type, Ordering)))

Sort-type can be: NUMERIC, TEXT, FREQUENCY, or LOAD_ORDER.

The Ordering types associated with each Sort-type are as follows:

Allowed ordering types
Sort-type Allowed Ordering types
NUMERIC ASCENDING, DESCENDING, or REVERSE
TEXT ASCENDING, A2Z, DESCENDING, REVERSE, or Z2A
FREQUENCY DESCENDING, REVERSE or ASCENDING
LOAD_ORDER ASCENDING, ORIGINAL, DESCENDING, or REVERSE

The ordering types REVERSE and DESCENDING are equivalent.

For Sort-type TEXT, the ordering types ASCENDING and A2Z are equivalent, and DESCENDING, REVERSE, and Z2A are equivalent.

For Sort-type LOAD_ORDER, the ordering types ASCENDING and ORIGINAL are equivalent.

Examples: Chart expressions using Aggr

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!