Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
benhumphrey
Contributor
Contributor

sum a field based on the max value of another field

Hi all,

I am trying to sum the Quantity Received based on the maximum price of the Component. Below is a table to try and demonstrate what I mean.

Component         Price        Qty

Product A            2.4            500

Product A            2.1            400

Product B            1.8            1000

So my dimension is component. And I have an expression to calculate the max price but I need to know how to then calculate the sum of the Qty bought in at the max price.

Any help is appreciated. Thank you in advance

31 Replies
MK_QSL
MVP
MVP

=FirstSortedValue(Distinct Aggr(Max(Qty),Component),-Aggr(Max(Cost),Component))


Aggr(Max(Cost),Component)

This will give you Max(Cost) for each component (i.e. Aggr is used)


You definitely wants Max(Qty) wherever Component is having Max Price appear more than once...


To use the same you need to have Distinct in front as the FirstSortedValue is having NoDistinct by default...


Hope this helps..



Not applicable

No problem! Good luck