Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
hitha1512
Creator
Creator

Assigning Rank in script

Hi Team,

Trying to get the below output(Rank) based on Sum(Sales) at the script level. 

Sale ID Sales Sum(Sales) Rank
1 20 20 1
2 20 20 1
3 40 40 2
4 50 50 3
5 50 50 3
6 70 70 4
7 80 80 5

 

Regards,

Hitha Dhani

Labels (1)
2 Solutions

Accepted Solutions
justISO
Specialist
Specialist

Hi, maybe something like this can be used, if your_table already has aggregated sales per [Sale ID]:

Final:
LOAD *,
AutoNumber(Sales) as Rank
RESIDENT your_table
ORDER BY Sales asc;

DROP TABLE your_table;

View solution in original post

brunobertels
Master
Master

Hi 

May be like this 

[Table]:

LOAD * INLINE
[
Sale ID,Sales,Sum(Sales),Rank
1,20,20,1
2,20,20,1
3,40,40,2
4,50,50,3
5,50,50,3
6,70,70,4
7,80,80,5
](delimiter is ',');

Rank:
load *,

autonumber(Sales) as Rank_Number

Resident Table order by [Sales] ;
drop table Table;

View solution in original post

3 Replies
justISO
Specialist
Specialist

Hi, maybe something like this can be used, if your_table already has aggregated sales per [Sale ID]:

Final:
LOAD *,
AutoNumber(Sales) as Rank
RESIDENT your_table
ORDER BY Sales asc;

DROP TABLE your_table;

brunobertels
Master
Master

Hi 

May be like this 

[Table]:

LOAD * INLINE
[
Sale ID,Sales,Sum(Sales),Rank
1,20,20,1
2,20,20,1
3,40,40,2
4,50,50,3
5,50,50,3
6,70,70,4
7,80,80,5
](delimiter is ',');

Rank:
load *,

autonumber(Sales) as Rank_Number

Resident Table order by [Sales] ;
drop table Table;

Iswarya_
Creator
Creator

Hi @hitha1512 ,

Please try by the below script:

Temp:
Load * Inline [
SaleID, Sales
1, 20
2, 20
3, 40
4, 50
5, 50
6, 70
7, 80
];

NoConcatenate
Final:
Load SaleID,
Sum(Sales) as Sales
resident Temp
Group by SaleID;
drop table Temp;

NoConcatenate
Final_1:
Load

SaleID,
Sales,
if(RecNo()=1,1,
      IF(Sales=Previous(Sales),Peek(Rank),
             IF(Sales<>Previous(Sales),Peek(Rank)+1))) as Rank
resident Final
Order by Sales;
drop table Final;

EXIT SCRIPT;

Iswarya__0-1658228465048.png