Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
thanhphongle
Creator II
Creator II

return max cost of product

Hello Community,

this is my table

Product
Cost
A10
B20
C5
D15
B20
A10
A10
C5
A10
D15

As you can see:

sum(Product A) = 40

sum(Product B) = 40

sum(Product C) = 10

sum(Product D) = 30

I want to create a textbox which returns the max sum(Cost). In this case it is A and B. Could anyone help me out how I can return both values?

It should return A = 40 and B = 40

1 Solution

Accepted Solutions
sunny_talwar

May be this:

=SubField(Concat(DISTINCT {<Product = {"=Aggr(Sum(Cost), Product) = Max(TOTAL Aggr(Sum(Cost), Product))"}>} Product, ','), ',', 1) & ' = '

& Max(TOTAL Aggr(Sum(Cost), Product))

& ' and ' &

SubField(Concat(DISTINCT {<Product = {"=Aggr(Sum(Cost), Product) = Max(TOTAL Aggr(Sum(Cost), Product))"}>} Product, ','), ',', 2) & ' = '

& Max(TOTAL Aggr(Sum(Cost), Product))

Capture.PNG

=Concat(DISTINCT {<Product = {"=Aggr(Sum(Cost), Product) = Max(TOTAL Aggr(Sum(Cost), Product))"}>} Product, ', ') & ' with a total sale of '

& Max(TOTAL Aggr(Sum(Cost), Product))

Capture.PNG

View solution in original post

3 Replies
Gysbert_Wassenaar

Try this: =concat(  aggr(only({<Product_={'=rank(sum(Cost))=1'}>}Product_) & ' = ' & sum({<Product_={'=rank(sum(Cost))=1'}>}Cost), Product_), ' and ')


talk is cheap, supply exceeds demand
sunny_talwar

May be this:

=SubField(Concat(DISTINCT {<Product = {"=Aggr(Sum(Cost), Product) = Max(TOTAL Aggr(Sum(Cost), Product))"}>} Product, ','), ',', 1) & ' = '

& Max(TOTAL Aggr(Sum(Cost), Product))

& ' and ' &

SubField(Concat(DISTINCT {<Product = {"=Aggr(Sum(Cost), Product) = Max(TOTAL Aggr(Sum(Cost), Product))"}>} Product, ','), ',', 2) & ' = '

& Max(TOTAL Aggr(Sum(Cost), Product))

Capture.PNG

=Concat(DISTINCT {<Product = {"=Aggr(Sum(Cost), Product) = Max(TOTAL Aggr(Sum(Cost), Product))"}>} Product, ', ') & ' with a total sale of '

& Max(TOTAL Aggr(Sum(Cost), Product))

Capture.PNG

sinanozdemir
Specialist III
Specialist III

Please see the attached.

Capture.PNG