Useful improvements of rank() function
recently, I had the chance to use the rank() function in order to assign a unique numeric id (sort of counter field) to values. In the current implementation, rank() assigns a number corresponding to the position in the sorted input list. Duplicate values are assigned the same rank. The rank of the value immediately following a repeated value x is x + (nr of repetitions-1), so that some rank numbers are skipped. In a template available on this site, an addition to the formula is shown giving a rank without skipped numbers for repeated values. What I would have needed in my recent application is yet another implementation, where the rank for repeated values remains the same, but the rank for the following value does not skip positions. In this way the rank identifies the position of a value in a list of sorted unique values.
An example may be useful (ranks are in ascending order):
input values: 12, 13, 15, 15, 15, 16, 16, 20
rank() as is now, : 1, 2, 3, 3, 3, 6, 6, 8
rank() modified: 1, 2, 3, 4, 5, 6, 7, 8 (as in template)
rank() unique: 1, 2, 3, 3, 3, 4, 4, 5 (requested feature)
It would be useful to add an optional argument to the rank() function in order to select one out of the three options.
Thanks in advance.
I’m having this similar issue, it would be good to bump it or is there a resolution?