# Advanced Ranking and Dynamically-Generated Named Sets in MDX

Calculating ranks is a classic MDX problem, and as is usually the case Mosha has an excellent blog entry on the subject which I would encourage you to read if you haven't done so already:

http://sqljunkies.com/WebLog/mosha/archive/2006/03/14/mdx_ranking.aspx

His advice can be summarised fairly simply - where possible declare a named set which is ordered to use in the Rank function rather than try to do this ordering every time you want to calculate a rank because it'll give you much better performance. This is all you need to know for 99% of the rank calculations you'll ever write; however, I've been doing a bit of thinking around the remaining 1% of scenarios and here's what I've come up with.