Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Madhusmita
Frequent Visitor

Rank calculation based on dynamic dimension parameter

HI Team,

 

Can anyone please help me with the below Rank calculation. 

 

Rank = RANKX(ALL(RESULTS[Country]),CALCULATE(SUM(RESULTS[CADRE POINTS]))) - Working
Rank = RANKX(ALL(p.Dimension[p.Dimension]),CALCULATE(SUM(RESULTS[CADRE POINTS]))) - Not Working
When i am passing the dimension name Country the rank is working fine but when i am using paramter as p.Dimension in place of Country it doesn't work.
 
Note: p.Dimension is a parameter that includes Country,Name,Region,Category. Basically i want to switch between these dimensions and the ranking changes based on the selected dimensions.
 
Thanks in advance
8 REPLIES 8
Madhusmita
Frequent Visitor

This is my P. Dimension Breakdown looks like

 

P.Dimension Breakdown = {
    ("Name", NAMEOF('RESULTS'[Name]), 0),
    ("Region", NAMEOF('RESULTS'[Region]), 1),
    ("Country", NAMEOF('RESULTS'[Country]), 2),
    ("Agency Network", NAMEOF('RESULTS'[Agency Network]), 3),
    ("Holding Company", NAMEOF('RESULTS'[Holding Company]), 4)
}
Madhusmita
Frequent Visitor

Hi Sahir,

 

as per your suggestion i created those calculations for each dimensions and tried to pass it all together but its throwing the below error. It looks like the p.Dimension breakdown parameter is not appearing when i try to use in the calculation 

Madhusmita_0-1676022470692.png

 

Sahir_Maharaj
Super User
Super User

This will return the correct rank based on the selected dimension in the parameter.

 

Let me know if you require any further assistance.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning
Sahir_Maharaj
Super User
Super User

Similarly, you can create measures for the Region and Category dimensions. Then, you can use a calculated column to switch between these measures based on the selected dimension in the parameter. For example:

 

Rank =
    SWITCH(
        p.Dimension,
        "Country", [Rank by Country],
        "Name", [Rank by Name],
        "Region", [Rank by Region],
        "Category", [Rank by Category],
        BLANK()
    )

 


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning
Sahir_Maharaj
Super User
Super User

For the Name dimension, you can create another measure:

 

Rank by Name = RANKX(ALL(RESULTS[Name]), CALCULATE(SUM(RESULTS[CADRE POINTS])))

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning
Sahir_Maharaj
Super User
Super User

To resolve this, you can create a separate measure for each dimension that you want to use for ranking and then switch between these measures based on the selected dimension in the parameter. For example, for the Country dimension, you can create the following measure:

 

Rank by Country = RANKX(ALL(RESULTS[Country]), CALCULATE(SUM(RESULTS[CADRE POINTS])))

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Hi Sahir,

 

Thank you for the response, so, instead of All what can i use?

 

 

Sahir_Maharaj
Super User
Super User

Hello @Madhusmita,

 

The issue is happening because the RANKX function expects a table expression as the first argument. When you use ALL(RESULTS[Country]), you are passing a table expression that includes only the Country column. However, when you use ALL(p.Dimension[p.Dimension]), you are passing a table expression that includes multiple columns (Country, Name, Region, and Category).


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.