Skip to main content Skip to complementary content

Nested aggregations

You may come across situations where you need to apply an aggregation to the result of another aggregation. This is referred to as nesting aggregations.

You cannot nest aggregations in most chart expressions. You can, however, nest aggregations if you use the TOTAL qualifier in the inner aggregation function.

Information note No more than 100 levels of nesting is allowed.

Nested aggregations with the TOTAL qualifier

Example:  

You want to calculate the sum of the field Sales, but only include transactions with an OrderDate equal to the last year. The last year can be obtained via the aggregation function Max(TOTAL Year(OrderDate)).

The following aggregation would return the desired result:

Sum(If(Year(OrderDate)=Max(TOTAL Year(OrderDate)), Sales))

Qlik Sense requires the inclusion of the TOTAL qualifier this type of nesting. It is necessary for the desired comparison. This type of nesting need is quite common and is a good practice.

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!