Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

Not applicable

Sum of Top n values in a text field

Hi all,

I'm trying to calculate the sum of the 5 largest values of one dimension. I tried set analysis and Aggr fuction combined with the Rank() function but did not succeed yet.

Attached a simple example of my problem:

  • 20 entries (line items) of "sales records".
  • 10 different customers
  • The TOP5 customers have a total of 51,446 sales.

This sum (51,446) is what I would like to calculate in a formula to replace the static blue coloured text.

Thank you!

topsums.PNG

1 Solution

Accepted Solutions
Not applicable

Re: Sum of Top n values in a text field

I'm still not sure why I was getting a different result in QV vs QS but the expression you need is this:

Copy directly into your app

SUM({<Customer={"=sum(Sales)>=$(=max(aggr(sum(Sales),Customer),5))"}>}Sales)

3 Replies
Not applicable

Re: Sum of Top n values in a text field

Hi David,

There seems something a bit odd going on here, I'm getting a different result from the same expression in QlikView vs QlikSense. 

The expression below works fine in QlikView (chart or text box) but in QlikSense it just seems to pick one value for a customer. Qlik monitor these threads so hopefully someone there can explain why?

sum({<Customer = {"=rank(sum(Sales))<=5"}>}  Sales) 

Hope this helped, thanks.

ramoncova06
Valued Contributor III

Re: Sum of Top n values in a text field

check this thread Customers Having Top 4 Values

Not applicable

Re: Sum of Top n values in a text field

I'm still not sure why I was getting a different result in QV vs QS but the expression you need is this:

Copy directly into your app

SUM({<Customer={"=sum(Sales)>=$(=max(aggr(sum(Sales),Customer),5))"}>}Sales)