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 QlikView chart expression. Nesting is only allowed if you:
- Use the TOTAL qualifier in the inner aggregation function.
Nested aggregations with the TOTAL qualifier
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 QlikView, but then again also necessary for the desired comparison. This type of nesting need is quite common and is a good practice.