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

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to sort a top N when using calculated dimension?

Hi,

I need to display the top N products by years in a bar chart and group the remaining products as 'other products'.

In order to do that, i'm using aggr() function in calculated dimension:

=aggr(if(rank(sum(Sales))<5, Product,'Other products'),Product)


This is working properly but the issue is that i'm not able to sort those products. I tried different formulas as sorting expression in the chart without any success...

Any idea on how to perform a sort here? (see the qvw attached)

Thanks in advance.

7 Replies
sathishkumar_go
Partner - Specialist
Partner - Specialist

HI

Please find the attachements.

I think it ll helpful for u.

Regards

Sathish

Not applicable
Author

I used the same approach for one of my tables. Is there a way to have the 'Others' bucket always display after the top N are sorted and displayed? This is the issue I am facing now.

Not applicable
Author

Hi,

It's easy to sort by Y-value when only one dimension is used. But my problem is more with the bar chart where "Year" is the first dimension and the aggr() dimension the second one.

In this case, the second dimension can be sorted using a specific "expression" but i'm not able to find the right formula. Whatever the expression i use, it has no effect on the product sorting in the bar chart.

Best Regards

deepakk
Partner - Specialist III
Partner - Specialist III

Hi Satish,

I have seen your application. How can I make the default 4 to a input from user.

When I am trying to use a variable its not working.

Deepak

Not applicable
Author

Hello,

In order to make the default 4 as an input, the only thing you need is to replace the 4 by the name of a variable in the calculated dimension expression. Then create an input box for this variable so that the user can change its value.

BR

deepakk
Partner - Specialist III
Partner - Specialist III

I got it... I was making a small error in setting the variable.

Not applicable
Author

Hi experts!

My problem is not solved. Any idea on how to sort when the second chart dimension is calculated dimension with aggr() function? (see bar chart in the initial post).

Thanks.