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

Announcements
April 13–15 - Dare to Unleash a New Professional You at Qlik Connect 2026: Register Now!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Top N

Hi,

I'm trying to create a straight table chart that will display a Top N (10). My dimension is customer and the expression is sum({<SYS_ID*={'ADVANCE_1LINK'}>} TXN_COUNT). As it is now its displaying all customers where I'm trying to show just the Top 10 based in the expression. I'm not sure of the syntax although I think I may need to use the Top function. I'm not sure of the syntax - any help would be greatly appreciated.

Also, do I need to use an input box or can I just hard code the expression to be top 10?

Thanks,

Shannon







1 Solution

Accepted Solutions
Miguel_Angel_Baeyens

Hello Shannon,

You may use the following as dimension, and leave the expression as it is:

=If(aggr(rank(aggr(sum({<SYS_ID*={'ADVANCE_1LINK'}>} TXN_COUNT), ID), 4, 2), CustomerID) <= 10, CustomerID)


You may need to change the code above, as the aggr() function used above must use the rest of dimensions in your chart. In my case there are two: ID and CustomerID.

By the way, you can use a variable instead of hardcoding the "10" so the user can select with, say, a slider object, the number of top customers he wants to display:

=If(aggr(rank(aggr(sum({<SYS_ID*={'ADVANCE_1LINK'}>} TXN_COUNT), ID), 4, 2), CustomerID) <= $(vTopNumber), CustomerID)


Hope that helps

View solution in original post

6 Replies
Miguel_Angel_Baeyens

Hello Shannon,

You may use the following as dimension, and leave the expression as it is:

=If(aggr(rank(aggr(sum({<SYS_ID*={'ADVANCE_1LINK'}>} TXN_COUNT), ID), 4, 2), CustomerID) <= 10, CustomerID)


You may need to change the code above, as the aggr() function used above must use the rest of dimensions in your chart. In my case there are two: ID and CustomerID.

By the way, you can use a variable instead of hardcoding the "10" so the user can select with, say, a slider object, the number of top customers he wants to display:

=If(aggr(rank(aggr(sum({<SYS_ID*={'ADVANCE_1LINK'}>} TXN_COUNT), ID), 4, 2), CustomerID) <= $(vTopNumber), CustomerID)


Hope that helps

Not applicable
Author

This is what I used for a dimension and it works great - thanks!

=If(aggr(rank(aggr(sum({<SYS_ID*={'ADVANCE_1LINK'}>} TXN_COUNT), CUST_NO), 4, 2), CUST_NAME) <= 10, CUST_NAME)

One last question: Is there a way to restrict the remaining rows? My straight table chart is displaying the CUST_NAME where they are in the top 10 and displaying a dash '-' when they are not. I would like to display only 10 rows. Full disclosure - I've had no Qlikview training but am scheduled to go next month.

Thanks again for your help.

Shannon

Miguel_Angel_Baeyens

Shannon, I'm glad to help. To avoid the null value showing, you can do any of the following:

If you don't want to accumulate the values for those who don't macth that top N, just select the calculated dimension and tick the checkbox "Supress When Value Is Null".

But if you want to show then as "Others" or "Not Top 10", you can set the "else" part in the if conditional

=If(aggr(rank(aggr(sum({<SYS_ID*={'ADVANCE_1LINK'}>} TXN_COUNT), CUST_NO), 4, 2), CUST_NAME) <= 10, CUST_NAME, 'Others')


Hope that helps.

johnw
Champion III
Champion III

If it's OK to sort your chart by the expression descending, then you can just set a max number of 10 on the presentation tab, and not have to fiddle with calculated dimensions.

Not applicable
Author

Perfect! Thanks again.

Not applicable
Author

That also makes sense. Thanks for the tip.