Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
AngieO2019
Contributor II
Contributor II

Rank (Sum) to scripts

Hi All,

I'm trying to convert this chart expression into script expression:

Rank(sum({<ID>} Score))

 

Any leads?

Labels (2)
1 Solution

Accepted Solutions
Kushal_Chawda

Can you tell me how do you want to Rank your score? If score is same then repeat the previous rank and for next rank increment the current row position?

Data:
LOAD
    ID,
    Score
FROM [lib://Data/SampleData.xlsx]
(ooxml, embedded labels, table is Sheet2);

Left Join(Data)
Load Count(DISTINCT ID) as TotalID
Resident Data;

Rank:
Load ID,
     sum(Score) as TotalScore
Resident Data
Group by ID;

Left Join (Data)
Load ID,
     TotalScore,
     if(RowNo()=1,1,if(TotalScore<>Peek(TotalScore),RowNo(),
     Peek(Rank)))as Rank
Resident Rank
Order by TotalScore desc;

Drop Table Rank;

Final:
Load *,
     (TotalID-Rank)/TotalID as Rank%
Resident Data;

Drop Table Data;

View solution in original post

5 Replies
Taoufiq_Zarra

can you share a sample data and the expected output ?

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
AngieO2019
Contributor II
Contributor II
Author

Hi, I can only provide this sample data.

The premise is that, depending on the percentage that the user will input on the input box, all IDs and Scores will be tagged as "Included".

 

the formula that I used on the chart in QlikView is:

If(

aggr(

(count({<ID>}Distinct Total ID) - Rank(sum({<ID>} Score))) / (count({<ID>}Distinct Total ID)-1)

,ID)
>= (1 - ($(Percentage)))

, Dual('Include',1))

 

 

I was able to translate the other functions in scripts, however, I'm having issues with the Rank(Sum) part...

Brett_Bleess
Former Employee
Former Employee

I may have inadvertently stumbled upon things I think, check the following Help link:

https://help.qlik.com/en-US/qlikview/April2020/Subsystems/Client/Content/QV_QlikView/Scripting/Aggre...

Regards,
Brett

To help users find verified answers, please do not forget to use the "Accept as Solution" button on any post(s) that helped you resolve your problem or question.
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.
Kushal_Chawda

Can you tell me how do you want to Rank your score? If score is same then repeat the previous rank and for next rank increment the current row position?

Data:
LOAD
    ID,
    Score
FROM [lib://Data/SampleData.xlsx]
(ooxml, embedded labels, table is Sheet2);

Left Join(Data)
Load Count(DISTINCT ID) as TotalID
Resident Data;

Rank:
Load ID,
     sum(Score) as TotalScore
Resident Data
Group by ID;

Left Join (Data)
Load ID,
     TotalScore,
     if(RowNo()=1,1,if(TotalScore<>Peek(TotalScore),RowNo(),
     Peek(Rank)))as Rank
Resident Rank
Order by TotalScore desc;

Drop Table Rank;

Final:
Load *,
     (TotalID-Rank)/TotalID as Rank%
Resident Data;

Drop Table Data;
AngieO2019
Contributor II
Contributor II
Author

Hi kush141087,

We were actually trying to replicate the PercentRank function of Excel. We thought that RangeFractile is the best bet to this, however, it seems like it only replicates the values in the Scores column.