Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikWorld, June 24-25, 2020. Free virtual event for DI and DA gurus. Register Today
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Creator II
Creator II

rank in script

Hello i am getting Count need Rank output thanks advance

IDColor CountRank
111blue44
111   
111blue43
111   
111   
111blue42
111   
111blue41
222   
222red33
222red32
222red31
222   
Labels (1)
1 Solution

Accepted Solutions
Highlighted
Partner
Partner

Re: rank in script

Right, no problem. 

 

Sort you table based on your count and then add: 

IF(ROWNO()=1,1,PEEK('Rank',-1)+1) AS Rank

It peeks at the previous rows and adds 1 to that number. When sorted at the correct count field you'll get a Rank. 

If you want to start a new count for every ID use this: 

IF(PEEK('ID',-1)<>ID,1,PEEK('Rank',-1)+1) AS Rank

View solution in original post

3 Replies
Highlighted
Partner
Partner

Re: rank in script

Hi @rajeshqvd

Basically you can start with: 

RANK(COUNT(Count))

The next step is using aggregates over color or ID, depending on what you need. 
For example: 

AGGR(RANK(COUNT(Count)),ID)

But based on the column count you won't get far because all the values are the same per ID. 

Highlighted
Creator II
Creator II

Re: rank in script

Need to build it in Script Not front end
Highlighted
Partner
Partner

Re: rank in script

Right, no problem. 

 

Sort you table based on your count and then add: 

IF(ROWNO()=1,1,PEEK('Rank',-1)+1) AS Rank

It peeks at the previous rows and adds 1 to that number. When sorted at the correct count field you'll get a Rank. 

If you want to start a new count for every ID use this: 

IF(PEEK('ID',-1)<>ID,1,PEEK('Rank',-1)+1) AS Rank

View solution in original post