Power BI

How to Use RANKX() for Dynamic Rankings in Power BI

How to use RANKX() For dynamic rankings in power bi

Table of Contents

Introduction

In Power BI, Use of RANKX() for dynamic rankings based on measures like sales, profit, or performance. One of its most powerful applications is for dynamic ranking, where results automatically update based on filters and slicers in reports.

In this blog post, you will learn how to build dynamic rankings system using RANKX() that makes your Power BI dashboards more insightful and interactive.

Want to learn more about DAX? Check out our blog: DAX in Power BI: As a formula language

What is RANKX() in Power BI?

RANKX() is used to rank entities over one another based on a measure value. It evaluates an expression for every row and gives a rank accordingly. When it is combined with a filter context function, it behaves more responsively and dynamically.

RANKX() for dynamic rankings
RANKX() evaluates an expression for every row and gives a rank accordingly

What is Dynamic Ranking?

Dynamic ranking means changing the rank of items based on user selections, allowing users to explore data more effectively.

Creating Dynamic Ranking Using RANKX()

For this demo, a Power BI exercise file is provided at the end that you can use to practice. Now that we have our data aligned, to see dynamic ranking in action.

Let’s create a ranking of customers based on country selection.

Step 1: Create a New Column

  • Right click on the Customer table in the Fields.
  • Click on New Column.

Column tools open.

  • Type the following formula in the formula bar and press Enter.

Country Wise Customer Ranking (CC ) =
RANKX (
ALLEXCEPT ( Customer, Customer[Country-Region] ),
[Total Sales Amount (CM)]
)

ALLEXCEPT() is used to leverage the power of RANKX(), meaning that it removes all filters from a table except the specified column (like Country). This ensures that ranking is calculated for the selected group only.

Learn about calculated columns in our blog: Calculated Columns in DAX

Step 2: Build the Visual

  • Click on the table visual in the visualization pane.
  • Drag and drop Customer from the Customer table to the Columns.
  • Drag and drop Total Sales Amount (CM) from All Measures table to the Columns.
  • Drag and drop Country Wise Customer Ranking (CC) from the Customer table to the Columns.
  • Right click on Country Wise Customer Ranking (CC) in Values and click on Don’t Summarize.
Table columns
Populating Table columns

Want to learn the difference between Power BI Table and Matrix? Check out our blog: Power BI Table vs Matrix

Step 3: Add a Slicer

  • Click on Slicer visual in the Visualization Pane.
  • Drag and drop Country-Region from Customer to the Field.

Step 4: Test the Dynamic Behaviour

  • Select a country (e.g., Australia).
  • Final dashboard view should be like:
RANKX() for dynamic rankings
Customer information along with sales amount and rankings are reflected with respect to country selected by the slicer dynamically.

Result:

  • Ranking updates instantly.
  • It starts from first rank within that country.
  • The visual ranks only customers from the selected country..

Best Practices for Dynamic Ranking

  • Use ALLEXCEPT() for rankings that are group-based.
  • ALL() can be used if you want to ignore filters altogether for global ranking.
  • For more flexibility it is preferred to use measures instead of columns.
  • Always test with slicers to confirm behaviour.

Conclusion

RANKX() function in Power BI is one of the most powerful DAX tools for creating ranks that are meaningful and based on any measures like sales, profits, or performance. When employed effectively, especially in when combined with filter context functions like ALLEXCEPT(), it enables dynamic ranking and results are adjusted automatically based on the selection. Mastering RANKX() is an important step in improving your DAX skills and building Power BI dashboards that are user-friendly and flexible.

FAQs

Dynamic ranking in Power BI updates ranks based on filters or slicers, unlike fixed ranking.

RANKX() uses ALLEXCEPT() to calculate ranks within the selected group, such as a country.

Power BI recommends using measures instead of columns for dynamic ranking scenarios.

Further Learning and Resources

To learn more about Power BI, check out our courses here: 

Want to learn how Microsoft 365 Copilot transforms everyday work with AI? Check out our Course:  

Want to learn more about Power BI and how to make reports more efficiently? 

Power BI training in Australia: We offer comprehensive training sessions across various cities, including: 

Ready to enhance your Power BI skills? Sign up for our training courses and explore our wide range of resources designed to elevate your data analytics capabilities.  

Want end-to-end solutions for your Power BI Reports? Get in touch with our consultants at Power BI Consulting Services in Australia

Contact Us: Make an enquiry about our Power BI courses and find the proper training for you.  

Leave a Reply

Your email address will not be published. Required fields are marked *