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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric 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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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