UPDATE: I posted the following before I saw the answer from @Joseph_Seddik , he is correct that you do not need rank to simply sort and select the top 10. However, if you actually needed to show a rank then the following would work.
I’ve been playing around with this and have the following suggestion, note that this only works if each row has a unique identifier with a consistent length. It is possible to create a rank without this constraint, but it makes the expression more complicated. In my case I am using a key called [UUID] which has an initial value of uniqueid() and therefore will always be 8 characters in length. [rank] would be a virtual column with the following expression:
As @Joseph_Seddik mentioned, the use of a slice with a row filter is the best way to get the list of top 10. However the slice itself is not ordered, therefore if you calculate a ranking based upon position in that slice, you have to repeat the order.
If you then need to have a ranking formula for a virtual column, then you could go with the following:
(1) The -1 is because of the way I am sorting and the list is getting converted to a string. Without it I believe I was seeing2 to 11, but try it out. If you are seeing 0 to 9 then yes, get rid of the -1.
(2) That is correct, the result of the count will be zero for anything outside the top 10.
(3) Changing the true to false will switch from descending to ascending, however you need to do that after you have isolated the top 10, otherwise you would end up ranking the bottom 10!. If you use the second expression in conjunction with the slice, then that would be fine, the slice would restrict the list to be just the top 10, then the subsequent expression could ranking them in the opposite order.
There is one weakness to my approach which I should let you know about. It does work with unique IDs of differing lengths, however it will fail if one ID can exist completely in another. For example if you had ID AB123456 and AB12345678 then the expression will fail to give the correct ranking.
Mr. Graham congratulations for your very, very nice answer. I was trying to ranking 368 cities and I could’not to build some good solucion like yours. Thanks a lot.