Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
ushakumari1_
Contributor
Contributor

Ranking in Backend

I need to rank this data in the table below in the backend. Can someone help?

Region Sales
North 5000
South 1500
East 1200
West 1800

 

Desired output

Region Sales Rank
North 5000 1
West 1800 2
South 1500 3
East 1200 4

 

Labels (1)
3 Replies
chriscammers
Partner - Specialist
Partner - Specialist

The important thing to remember here is that you have to do two operations which you can do simultaneously but one of them has a restriction. The first operation to to sort the records the second is to figure out the rank.

 

When you load data you can use an "order by" clause but this clause only works on data that is loaded via a resident load.

So no matter what you do this is going to have to be a two step process.

  1. Load the data in RAM
  2. Sort and rank the data

 

Temp:
Load * Inline [
Region,Sales
North,5000
South,1500
East,1200
West,1800
]

Ranked:
Load
   Region,
   Sales,
   RowNo() as Rank
Resident Temp
Order by Sales Desc;
Drop Table Temp;

 

the RowNo function provides an autonumber based on the sequence of the records in the resulting table.

Vegar
MVP
MVP

The solution from @chriscammers  should solve your issue as you described it.

You could also have a look at the quite new  WRank.

chriscammers
Partner - Specialist
Partner - Specialist

@Vegar Any idea when wRank was? Depending on how recent any idea if it has made it to Qlik Sense on Windows??

I definitely would have suggested WRank had I known about it.

 

If you don't have WRank on your version then to serve the partition function you can use Autonumber(Value,PartitionDimension) instead of Rowno().