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.

As a general rule, it is not allowed to nest aggregations in a Qlik Sense chart expression. Nesting is only allowed if you:

  • Use the TOTAL qualifier in the inner aggregation function.
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))

The inclusion of the TOTAL qualifier is absolutely necessary for this kind of nesting to be accepted by Qlik Sense, but then again also necessary for the desired comparison. This type of nesting need is quite common and is a good practice.

Did this information help you?

Thanks for letting us know. Is there anything you'd like to tell us about this topic?

Can you tell us why it did not help you and how we can improve it?