How to use the DAX RANKX Function in Power BI
- Bernard Kilonzo

- Aug 13
- 2 min read
Updated: Aug 18

Overview
The RANKX function in Power BI is a DAX function used to calculate the rank of an expression within a table. It is particularly useful for ranking items based on a specific measure, such as sales, profit, or quantity.
The Syntax
RANKX(<Table>, <Expression>, [<Value>], [<Order>], [<Ties>])<Table>: The table to iterate over.
<Expression>: The calculation to rank (e.g., SUM(Sales)).
<Value> (optional): A specific value to rank; usually omitted.
<Order> (optional): Use ASC for ascending or DESC for descending (default is DESC).
<Ties> (optional): Use SKIP or DENSE to handle tied ranks.
Example: Ranking Product Sub-Category by Sales
To rank product sub-categories by sales. Create a measure “Total Sales” as shown below.
Total Sales = SUM(Orders[Sales])Create other measures “Rank_ALL” and “Rank_ALLSELECTED” as shown below.
Rank_ALL = RANKX(ALL(Orders[Sub-Category]),[Total Sales], ,DESC, Dense)Rank_ALLSELECTED = RANKX(ALLSELECTED(Orders[Sub-Category]),[Total Sales], , DESC, Dense)Note I have used ALL(Orders [Sub-Category]) to rank across all products sub-categories ignoring any filters in the view.
While ALLSELECTED(Orders [Sub-Category]) is used to rank only the selected products on the filters card.
Build your views.
Add a table visual in Power BI.
Include Sub-Category, Total Sales, and Rank_ALL
Sort the table by Rank_ALL to see the top performing product sub-categories by Sales.
Build a similar table visual but now using Rank_ALLSELECTED.
Add a Sub-Category slicer.

From the above view, you can see that Rank_ALL ignores the selected filters when computing the rankings (rankings are computed out of all the products) while Rank_SELECTED ranks the table based on the selected filters.
Conclusion
The RANKX function in Power BI is more than just a tool for ordering data - it’s a gateway to deeper, more actionable insights. Whether you're identifying top-performing products, segmenting high-value customers, or visualizing performance trends across time and geography, RANKX empowers you to transform raw numbers into meaningful narratives.
By mastering its syntax and understanding how to apply it within different contexts - such as using ALL to remove filters, choosing between DENSE and SKIP for tie handling, and combining it with other DAX functions - you gain the flexibility to build dynamic, responsive reports that adapt to user interaction and business needs.
In a world where data-driven decisions are paramount, ranking metrics effectively can highlight what truly matters. With RANKX, you’re not just sorting data - you’re surfacing priorities, revealing patterns, and enabling smarter strategies.
So, whether you're building dashboards for executives or crafting detailed analytical models, integrating RANKX into your Power BI toolkit is a step toward more intelligent, impactful reporting.
If you like the work we do and would like to work with us, drop us an email on our contacts page and we’ll reach out!
Thank you for reading!
