Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
pra_kale
Creator III
Creator III

How to Give Rank within a Group

Hi,

I want to give a rank according to Sales but not on overall but within a groups. for e.g. I want a rank within a group for sales in Traditional, Ulip and Saving.

I have tried with a below given logic but by this logic I am getting a rank overall where as my requirement is within a Group..

A:

LOAD Product,

     Sub_Product,

     Sale

FROM

(ooxml, embedded labels, table is Sheet1);

NoConcatenate

B:

LOAD *,

AutoNumber(Sale) as Rank

Resident A Order by Sale desc;

DROP Table A;

EXIT Script

Thanks in advance.

1 Solution

Accepted Solutions
Kushal_Chawda

your script looks ok. Only change you need is below

AutoNumber(Sale,Product) as Rank

View solution in original post

6 Replies
mightyqlikers
Creator III
Creator III

HI,

PFA.

$@

Digvijay_Singh

You can try this at front end, I don't have licensed version so cannot view qvw, below image can help, Product/SubProduct are chosen as dimension in straight table -

Capture.JPG

Kushal_Chawda

your script looks ok. Only change you need is below

AutoNumber(Sale,Product) as Rank

pra_kale
Creator III
Creator III
Author

Thanks Kush working fine..Thanks Sam and Digvijay Too.

msteedle
Luminary Alumni
Luminary Alumni

This approach gives the correct results, but is incredibly slow for anything but the smallest data volume. I wrote this up here: https://www.michaelsteedle.com/2019/04/ranking-within-group-quickly-in-qlik.html

TL;DR This is >99% faster: 

If(Product = Previous(Product), Peek(Rank) + 1, 1) as Rank

 

nick_creek
Contributor
Contributor

Thanks Mike,

Great solution. Took a little while to find this, so a 'like' might help future searchers.

Nice work & website too.

Thanks, nick