Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Issue in displaying top2 values

Hi,

I had a issue in displaying Top 2 values. I had a table with ID, Country, Amount. I would like to take Top 2 ID's based on Amount.

Load * inline

[ID, Country, Amount

1,'India', 20

2,'UK',40

1,'UK',10

1,'Europe',30

3,'USA',50

3,'India',60

4,'UK',10

5,'India',0

];

In a straight table, I have ID, Country as dimensions and sum(Amount) as expression. I have sorted ID field based on Expression sum(Amount).

Output:

ID, Country, Amount

3,'India',60

3,'USA',50

1,'Europe',30

1,'India', 20

1,'UK',10

Please advise.

Thanks & Regards,

Devaki

15 Replies
Not applicable
Author

Hi swuehl,

I got the rank as expected with your query.

IDCountrySUM(Amount)Rank
220-
3India601
3USA501
1Europe302
1India202
1UK102
2UK400
4UK100

But could you let me know how to restrict the number of rows of table to rank<=2.This might be easy but i did not get the idea how to restrict it.

Hi Miikka,

I want to get Top2 IDs(for example, Companies) which are performing well based on sum(Amount).

swuehl
MVP
MVP

Maybe try

if(column(2)>0, sum(Amount))

instead of your sum(Amount) expression. And check suppress zero values in presentation tab.

Not applicable
Author

Suppress Zero values is not working. Also I cannot suppress Zero values as i have some IDs with Zero Amount.

swuehl
MVP
MVP

You might try this as caclulated dimension instead of ID

=aggr(NODISTINCT if(rank(sum(total<ID> Amount))<=2,ID),ID)

check suppress when value is NULL on dimension tab.

EDIT: As calculated dimension, it should be possible to simplify above to

=aggr(if(rank(sum(Amount))<=2,ID),ID)

Not applicable
Author

It is working. You are a Genius.

Thank you.

Not applicable
Author

Hi,Swuehl   Exlent,Thx