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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
vijay_27
Helper I
Helper I

Need to correct sequence of Rank on excluding the value selected in slicer

I have three tables in my data model:

Calendar Table: Having date Column
Fact Table: Having Branch, Dist, Order Date, Region, Qty Columns
Branch Table:Having Branch Column

In Report,

A Filter for Branch from Branch Table

A Table visual is created in which we are calculating Rank based on a Measure below:

6 Month Capacity = (CALCULATE(SUM('Fact'[Qty]),calendar[Date]=EOMONTH(TODAY(),-1))
+ CALCULATE(SUM('Fact'[Qty]),calendar[Date]=EOMONTH(TODAY(),-2))
+ CALCULATE(SUM('Fact'[Qty]),calendar[Date]=EOMONTH(TODAY(),-3))
+ CALCULATE(SUM('Fact'[Qty]),calendar[Date]=EOMONTH(TODAY(),-4))
+ CALCULATE(SUM('Fact'[Qty]),calendar[Date]=EOMONTH(TODAY(),-5))
+ CALCULATE(SUM('Fact'[Qty]),calendar[Date]=EOMONTH(TODAY(),-6)))

Rank is calculated as below:

Rank =
VAR Ran =
RANKX(ALL('Fact'[Branch],'Fact'[Dist],'Fact'[Region]),'Table'[6 Month Capacity],,desc)
Return ran

I have created another measure to exclude the branch in Table whatever is selected in the filter:

Exclude Branch = IF(MAX('Fact'[Branch]) IN ALLSELECTED(Branch[Branch])&&
COUNTROWS(ALLSELECTED(Branch[Branch])) <> COUNTROWS(ALL(Branch[Branch])),
"Y","N")

When I put Exclude Branch="N" in filter pane, then Rank got disturbed:

Is there way to correct this Rank when we exclude the branch in table based on filter selection, or either way
to create any index such that it in sequence with no rank missing.

Please find the .pbix attachment.
https://drive.google.com/file/d/1ZIPB_KDNXsSZsucjDH91j8HvhoM9Jm4p/view?usp=sharing

Below output I want

tempsnip.png

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

Hi @vijay_27 ,

 

You just need to add a filter in your Rank measure.

Try this code, it will still work even if you want to do multiple selection in your slicer.

Rank2 = 
VAR _SelectBranch =
    VALUES ( Branch[Branch] )
VAR _RANK =
    RANKX (
        FILTER ( ALL ( 'Fact' ), NOT ( 'Fact'[Branch] IN _SelectBranch ) ),
        [6 Month Capacity],
        ,
        DESC
    )
RETURN
    _RANK

Result is as below.

Select "t" in slicer:

1.png

Select "e" and "t" in slicer:

2.png

Best Regards,
Rico Zhou

 

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

4 REPLIES 4
v-rzhou-msft
Community Support
Community Support

Hi @vijay_27 ,

 

You just need to add a filter in your Rank measure.

Try this code, it will still work even if you want to do multiple selection in your slicer.

Rank2 = 
VAR _SelectBranch =
    VALUES ( Branch[Branch] )
VAR _RANK =
    RANKX (
        FILTER ( ALL ( 'Fact' ), NOT ( 'Fact'[Branch] IN _SelectBranch ) ),
        [6 Month Capacity],
        ,
        DESC
    )
RETURN
    _RANK

Result is as below.

Select "t" in slicer:

1.png

Select "e" and "t" in slicer:

2.png

Best Regards,
Rico Zhou

 

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

CNENFRNL
Community Champion
Community Champion

Easy one; what's more, viz-level filter is not necessary. One measure does the trick,

CNENFRNL_1-1641225365580.png

 


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Along with rank we also need 6 month capacity

amitchandak
Super User
Super User

@vijay_27 , I doubt you can make exclude work easily without using an independent table 

 

I have discussed an example here

Need of an Independent Table in Power BI: https://youtu.be/lOEW-YUrAbE

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

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