Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Data Works for AI is here - Join the discussion and enter to win a pair of Qlik kicks: Join the Conversation!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Need to calculate Dense Rank

Hello,

I am making a sports result ranking and need to calculate a dense rank (eg. 1,2,3,4,4,5,6,7,8,8,8,9) based on value from two columns (Poeng and Innertreff).

My table looks like this:

NavnPoengInnertreff
Anders759
Øyvind7014
Ole Petter7014
Anders7010
Jo6612
Arne6220
Hans5919
Thor5919

I want to add a column with DenseRank like this:

DenseRankNavnPoengInnertreff
1Anders759
2Øyvind7014
2Ole Petter7014
3Anders7010
4Jo6612
5Arne6220
6Hans5919
6Thor5919

Anyone who can help me with this?

Labels (1)
18 Replies
Nicole-Smith
MVP
MVP

This should do the trick:

data:

LOAD * INLINE [

    Navn,Poeng,Innertreff

    Anders,75,9

    Øyvind,70,14

    Ole Petter,70,14

    Anders,70,10

    Jo,66,12

    Arne,62,20

    Hans,59,19

    Thor,59,19

];

final:

LOAD *, if(previous(Innertreff)=Innertreff,peek('DenseRank'),rangesum(peek('DenseRank'),1)) as DenseRank

RESIDENT data

ORDER BY Poeng desc;

drop table data;

Not applicable
Author

Robert,

you need it in load script or in UI?

regards

Darek

Not applicable
Author

Hi, it would be best to have it in UI, as I will use various selections and I want to rank different selections. There is gonna be a lot of data added, so inline loading of the table isn't practical.

Thanks

Not applicable
Author

Do you expect that both fields are integers?

Not applicable
Author

yes, they are

Not applicable
Author

i thik, something like:

rank(Poeng+max(total Innertreeff) + Innertreeff)

should give expected results.

regards

Darek

Not applicable
Author

Robert,

in fact use:

dimension: Navn

expression: rowno()


and sort your result by expression:

Poeng+max(total Innertreeff) + Innertreeff


regards

Darek

Not applicable
Author

sorry:

expression like:

rank(Poeng+ Innertreeff / max(total Innertreeff) )


will be better.



Not applicable
Author

After a bit of trying, I have come to the conclusion that I have to resolve this in the load script.

I've tried using Nicoles code, but I get an error when I Reload data.

Field not found

final:

LOAD *, if(previous(Innertreff)=Innertreff,peek('Plass'),rangesum(peek('Plass'),1)) as Plass

RESIDENT data

ORDER BY Poeng desc, Innertreff desc

This is the load script:

data:

LOAD * INLINE [

Dato

Stevne

Dato

Navn

Forening

Poeng

Innertreff

Merknad

];

final:

LOAD *, if(previous(Innertreff)=Innertreff,peek('Plass'),rangesum(peek('Plass'),1)) as Plass

RESIDENT data

ORDER BY Poeng desc, Innertreff desc;

drop table data;