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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
testyuiiop
Helper I
Helper I

Rank based on dynamic slicer selection

Hi All,

I have a sales table, and I am ranking my customers based on below dax:

    RANKX(
        ALLSELECTED(Sales[Cust ID],Sales[Cust Name])
        ,[Total Sales]
        ,
        ,ASC
    )

I also have two slicers on my report , one which will filter customer location and another year. I have only one sales table and all columns are coming from it. When I don't select anything it give the correct ranking but when I apply filter on the slicers it doesn't work. How I can make the rank function work based on filter selection?

1 ACCEPTED SOLUTION
v-xuxinyi-msft
Community Support
Community Support

Hi @testyuiiop 

 

@lbendlin , thanks for your concern about this case.

 

I’d like to acknowledge the valuable input provided by the @Sahir_Maharaj. His initial idea was instrumental in guiding my approach. However, I noticed that further details were needed to fully understand the issue.
In my investigation, I took the following steps:

 

My sample:

vxuxinyimsft_2-1711952129542.png

 

I created two new tables for each of the two slicers.

vxuxinyimsft_0-1711952068283.png

 

vxuxinyimsft_1-1711952097260.png

 

There is no relationship between the three tables.

vxuxinyimsft_3-1711952193423.png

 

I also created a following formula just to get the measure.

 

Total Sales = CALCULATE(SUM(Sales[Sales]), ALLEXCEPT(Sales, Sales[Cust Name]))

 

 

Create a measure as follows

 

rank = RANKX(ALLSELECTED(Sales), [Total Sales], , ASC, Dense)

 

 

Result:

vxuxinyimsft_4-1711952555660.png

 

vxuxinyimsft_5-1711952580859.png

 

@testyuiiop , if this sample data is structurally different from the one you are using, please do not hesitate to mention it and I will modify it!

 

Best Regards,
Yulia Xu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-xuxinyi-msft
Community Support
Community Support

Hi @testyuiiop 

 

@lbendlin , thanks for your concern about this case.

 

I’d like to acknowledge the valuable input provided by the @Sahir_Maharaj. His initial idea was instrumental in guiding my approach. However, I noticed that further details were needed to fully understand the issue.
In my investigation, I took the following steps:

 

My sample:

vxuxinyimsft_2-1711952129542.png

 

I created two new tables for each of the two slicers.

vxuxinyimsft_0-1711952068283.png

 

vxuxinyimsft_1-1711952097260.png

 

There is no relationship between the three tables.

vxuxinyimsft_3-1711952193423.png

 

I also created a following formula just to get the measure.

 

Total Sales = CALCULATE(SUM(Sales[Sales]), ALLEXCEPT(Sales, Sales[Cust Name]))

 

 

Create a measure as follows

 

rank = RANKX(ALLSELECTED(Sales), [Total Sales], , ASC, Dense)

 

 

Result:

vxuxinyimsft_4-1711952555660.png

 

vxuxinyimsft_5-1711952580859.png

 

@testyuiiop , if this sample data is structurally different from the one you are using, please do not hesitate to mention it and I will modify it!

 

Best Regards,
Yulia Xu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

testyuiiop
Helper I
Helper I

@lbendlin 

 

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

testyuiiop
Helper I
Helper I

no this doesn't work

Sahir_Maharaj
Super User
Super User

Hello @testyuiiop,

 

Can you please try this:

 

Customer Rank = RANKX(
    ALLSELECTED(Sales), 
    [Total Sales], 
    , 
    ASC, 
    DENSE
)

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?
➤ Lets connect on LinkedIn: Join my network of 13K+ 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
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.