Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Saurabh07
Contributor III
Contributor III

Get top 5 dimensions in Line chart

Hello Gurus,

I have a dataset with 5 months of values for different countries. 

DateCountryValue
01-01-2020Australia4121
01-01-2020Germany1092
01-01-2020Italy2475
01-01-2020Jersey1548
01-01-2020Luxembourg2102
01-01-2020Netherlands1290
01-01-2020Singapore4142
01-01-2020Switzerland261528
01-01-2020United Kingdom10398
01-01-2020United States of America78009
01-02-2020Australia5024
01-02-2020country_unassigned30105
01-02-2020Germany5442
01-02-2020Luxembourg4924
01-02-2020Netherlands3677
01-02-2020Singapore3436
01-02-2020Switzerland18535
01-02-2020United Kingdom13358
01-02-2020United States of America89225
01-02-2020Virgin Islands (Brit)4277
01-04-2020Canada8823
01-04-2020country_unassigned48637
01-04-2020France11286
01-04-2020Germany11970
01-04-2020Japan7714
01-04-2020Luxembourg14027
01-04-2020Netherlands7277
01-04-2020Switzerland112202
01-04-2020United Kingdom37741
01-04-2020United States of America155936
01-05-2020Australia5388
01-05-2020country_unassigned318186
01-05-2020Germany5636
01-05-2020Luxembourg3127
01-05-2020Netherlands3327
01-05-2020Singapore3498
01-05-2020Switzerland20748
01-05-2020United Kingdom13776
01-05-2020United States of America90066
01-06-2020Virgin Islands (Brit)4046
01-06-2020Australia3458
01-06-2020Canada2739
01-06-2020country_unassigned343785
01-06-2020France2693
01-06-2020Germany5535
01-06-2020Luxembourg2450
01-06-2020Netherlands2882
01-06-2020Switzerland18619
01-06-2020United Kingdom9143
01-06-2020United States of America88556

I want to see only TOP 5 countries in line chart. But when I plot the same in Qlik, I get unexpected results.

Saurabh07_0-1603711502616.png

I have applied limit on the dimension to get Top 5 only, still 8 countries are being plotted. Not sure why? Can anyone please help me here?

1 Solution

Accepted Solutions
Kushal_Chawda

@Saurabh07  try below

=aggr(if( rank(sum({<status={"Class1"}>}Value))<6,Country),Country)

View solution in original post

5 Replies
Kushal_Chawda

@Saurabh07  create calculated dimension for Country like below

=aggr(if( rank(sum(Value))<6,Country),Country)

Note: check "suppress when value is NULL" option

Saurabh07
Contributor III
Contributor III
Author

Hello @Kushal_Chawda This almost worked for me, except for I forgot to mention one more constraint in my data.

Below is the class assigned to each country;

CountryStatus
AustraliaClass1
GermanyClass1
ItalyClass2
JerseyClass1
LuxembourgClass1
NetherlandsClass2
SingaporeClass2
SwitzerlandClass1
United KingdomClass2
United States of AmericaClass1
country_unassignedClass1
Virgin Islands (Brit)Class2
CanadaClass1
FranceClass2
JapanClass2

So I need to get Top 5 countries for Class1 countries, I combined your query with another if but its not giving any result:

=if(Status = 'Class1', aggr(if( rank(sum(Value))<6,Country),Country))

Can you suggest something here please ?

Kushal_Chawda

@Saurabh07  try below

=aggr(if( rank(sum({<status={"Class1"}>}Value))<6,Country),Country)

Saurabh07
Contributor III
Contributor III
Author

@Kushal_Chawda It worked like magic, I need to work a lot on my set analysis knowledge to be able to write such expressions in first place! Thanks a ton Man!

Saurabh07
Contributor III
Contributor III
Author

Hello @Kushal_Chawda, there is another doubt here if I may ask, what if I want to exclude Australia and Jersey all together from my calculations. I can think of -= function here , but not sure how?