The TOPN feature is accessible directly from the Power BI user interface and allows users to filter visuals to show the top N items based on a measure like total sales.
While easy to use, TOPN has a major limitation: it does not respect filter context. For example, if you filter by year, the same top countries (e.g., Australia, UK, USA) appear for every year, regardless of actual performance in that year.
To overcome the limitations of TOPN, Mitchell introduces the RANKX function in DAX. This function allows for dynamic ranking that respects all filters applied in the report.
Country Rank
).RANKX
function with a table expression like ALL(Geography[Country])
.Total Sales
.For example, in 2005, the top countries might be Australia, USA, and UK, but in 2006, the list could change to Australia, USA, and Canada—accurately reflecting the data.
Mitchell also demonstrates how to filter visuals using a measure like Country Rank
:
is less than or equal to 3
to show only the top 3 ranked items.This method ensures that the top N results are dynamically calculated based on the current filter context, unlike the static behavior of TOPN.
Mitchell also shares that you can:
REMOVEFILTERS
instead of ALL
for more control.This video is a must-watch for Power BI users who want to understand the nuances of ranking data. Whether you're building dashboards or detailed reports, knowing when to use TOPN versus RANKX can make a big difference in the accuracy and flexibility of your visuals.
Don't forget to check out the Pragmatic Works' on-demand learning platform for more insightful content and training sessions on DAX and Power BI and other Microsoft applications. Be sure to subscribe to the Pragmatic Works YouTube channel to stay up-to-date on the latest tips and tricks.