Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Aggregating cost based on highest cost

Hello,

I'm trying to sum the costs, per customer account, based on the highest single cost for that customer.

For example,

AccountReasonManagerYear Purchase CountDepartmentCost Code
023197775Reason1Manager120141Dept11671496369
023197775Reason2Manager120141Dept1481520254
023197775Reason2Manager120141Dept113461525959
023197775Reason3Manager120141Dept1881548046
023197775Reason4Manager220141Dept2861591761
5 1735

What I'm trying to get is 1 row with the total cost where the max cost is, per account:

AccountReasonManagerYearPurchase CountDepartmentCostCode
023197775Reason2Manager120141Dept117351525959
51735

Can anyone help with this?

1 Solution

Accepted Solutions
4 Replies
Clever_Anjos
Employee
Employee

Please check functions FirstSortedValue() and Max(), they should return what you need

Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

This is so called Nested Aggregation, and it requires the use of the Advanced Aggregation function AGGR(). Essentially, you need to pre-aggregate your costs per Customer (possibly also per Reason, Manager, and Year) and then aggregate again and get the Max of these pre-aggregated numbers. So, something like this should work:

Max(

     AGGR(

               sum(Cost),

               Account, Reason, Manager, Year

     )

)

AGGR() is one of the least documented functions. I teach a half-day lecture at the Masters Summit for QlikView, just on AGGR() and Set Analysis. I also describe it in detail in my new book QlikView Your Business.

cheers,

Oleg Troyansky

QlikView Your Business: An expert guide to Business Discovery with QlikView and Qlik Sense

Clever_Anjos
Employee
Employee

PFA

Anonymous
Not applicable
Author

This works! It's unfortunate that the dimensions are no longer selectable but I'm working on putting those expressions in the load script.  Thank you!