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
TotalAnonymous
Frequent Visitor

RankX with Multiple Slicer

Hi everyone, hope you're doing well.

I have an issue regarding RANKX DAX while applying several slicers. Please kindly find the image below:

TotalAnonymous_1-1714377681560.png

 

As you can see my DAX is not working properly. The rank is supposed to be flexible depends on the selected item on each slicer.
Here is my DAX:

TotalAnonymous_2-1714377772647.png

 

And here is the data model:

TotalAnonymous_0-1714377610593.png

Even though using the sample data, I try to create a similar data model like the original one. Do you have any idea what makes my DAX not working properly? Thank you for your help!


You can find the PBIX file here

1 ACCEPTED SOLUTION

@TotalAnonymous,

 

RANK automatically considers the filter context from other fields such as Company (be sure to use Company Master[Company] in the visual). I added an IF statement to exclude non-existent combinations of Company/SKU:

 

Rank Sales = 
IF (
    // rank only Company/SKU combinations that have sales
    NOT ISBLANK ( [Total Sales] ),
    RANK (
        DENSE,
        ALLSELECTED ( 'SKU Master' ),
        ORDERBY ( [Total Sales], DESC, 'SKU Master'[SKU Code] )
    )
)

 

DataInsights_0-1714492818659.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
DataInsights
Super User
Super User

@TotalAnonymous,

 

Try this measure using RANK. It's a better choice than RANKX in most cases.

 

Rank Sales = 
RANK (
    DENSE,
    ALLSELECTED ( 'SKU Master' ),
    ORDERBY ( [Total Sales], DESC, 'SKU Master'[SKU Code] )
)

 

DataInsights_0-1714401785937.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @DataInsights , Thank you for your help! your DAX works properly.

TotalAnonymous_0-1714438209136.png

I have one more question, I've added a "company" field into my table. However, it turns out that the DAX is not considering rank between companies. Do you know how to fix it? Thank you! 

@TotalAnonymous,

 

RANK automatically considers the filter context from other fields such as Company (be sure to use Company Master[Company] in the visual). I added an IF statement to exclude non-existent combinations of Company/SKU:

 

Rank Sales = 
IF (
    // rank only Company/SKU combinations that have sales
    NOT ISBLANK ( [Total Sales] ),
    RANK (
        DENSE,
        ALLSELECTED ( 'SKU Master' ),
        ORDERBY ( [Total Sales], DESC, 'SKU Master'[SKU Code] )
    )
)

 

DataInsights_0-1714492818659.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.