Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
alanwong1178
Contributor III
Contributor III

rank for group

CountryCitySalesRank for cityRank for country
GBLHR50113
GBMAN2093
USNYC30041
USLAX20051
USSFO30431
CNSHA10084
CNPEK11574
JPTYO50022
JPOSK14962

 

I would like to do two ranking column. One for rank for all city. Another rank is based on total of each country.

Please kindly help. Thanks.

Also, I would like to do a dynamic top N for country field. This means that if I set to get top 2, result can be shown as below.

 

CountryCitySalesRank for cityRank for country
USNYC30041
USLAX20051
USSFO30431
JPTYO50022
JPOSK14962

 

 

 

 

Labels (3)
1 Reply
GaryGiles
Specialist
Specialist

You need to incorporate the aggr() function into your expressions.

For Rank for City, you could use the following in a dimension expression:

=aggr(Rank(sum({1} Sales)), City)

 

For Rank for Country, you could use the following in a dimension expression:

=if(aggr(Rank(sum({1} Sales)), Country)<=2,aggr(Rank(sum({1} Sales)), Country))

The if statement is for picking the dynamic top N for the Rank in Country.  To make it dynamic, you will need to replace the "2" with the variable you will use to set the Top N.  You will also need to uncheck "Include null values" for this expression.