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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
M_Aird
Frequent Visitor

RANKX exclude from rank, but include in table

Hi all,

I have written the following RANKX DAX formula to rank States by current month value. The resulting table is below:

 

State ranking (asc) = RANKX(ALLSELECTED('Current_month_labourforce'),calculate(Sum(Current_month_labourforce[Current month value])),,ASC)

table.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

What I'd like to do is exclude 'Australia' from the ranking, but still include it in the table showing a blank under rank. I would also like Australia to always be at the bottom of the table. I've attempted 'ALLEXCEPT' formulas etc but that results in the total exclusion of 'Australia' from the table.

 

My State and territory field sits in a table called State. So, 'State'[State and territory]...

 

Any help greatly appreciated.

 

cheers

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @M_Aird

 

Here's an idea that should work without changing your existing tables:

(sample pbix uploaded here)

 

  1. Change your rank measure to this (updated slightly to rank over the State table as well as return blank result for Australia):
    State ranking (asc) = 
    IF (
        SELECTEDVALUE ( State[State and territory] ) <> "Australia",
        RANKX (
            CALCULATETABLE (
                ALLSELECTED ( State ),
                State[State and territory] <> "Australia"
            ),
            CALCULATE ( SUM ( Current_month_labourforce[Current month value] ) ),
            ,
            ASC
        )
    )
  2. Add a "dummy" measure to rank the final table, which always gives Australia the highest possible rank:
    R = 
    IF (
        SELECTEDVALUE ( State[State and territory] ) = "Australia",
        COUNTROWS ( ALLSELECTED ( State ) ),
        [State ranking (asc)]
    )
  3. Create a table containing R, State ranking (asc), State and territory and Current month value
  4. Sort by R
  5. Reduce the width of the R column heading until it is invisible.
  6. Result looks like this:image.png

     

Well that's one method anyway. You could also add a special flag to the State table to flag Australia as being excluded from the ranking.

 

Cheers,

Owen 🙂


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

3 REPLIES 3
OwenAuger
Super User
Super User

Hi @M_Aird

 

Here's an idea that should work without changing your existing tables:

(sample pbix uploaded here)

 

  1. Change your rank measure to this (updated slightly to rank over the State table as well as return blank result for Australia):
    State ranking (asc) = 
    IF (
        SELECTEDVALUE ( State[State and territory] ) <> "Australia",
        RANKX (
            CALCULATETABLE (
                ALLSELECTED ( State ),
                State[State and territory] <> "Australia"
            ),
            CALCULATE ( SUM ( Current_month_labourforce[Current month value] ) ),
            ,
            ASC
        )
    )
  2. Add a "dummy" measure to rank the final table, which always gives Australia the highest possible rank:
    R = 
    IF (
        SELECTEDVALUE ( State[State and territory] ) = "Australia",
        COUNTROWS ( ALLSELECTED ( State ) ),
        [State ranking (asc)]
    )
  3. Create a table containing R, State ranking (asc), State and territory and Current month value
  4. Sort by R
  5. Reduce the width of the R column heading until it is invisible.
  6. Result looks like this:image.png

     

Well that's one method anyway. You could also add a special flag to the State table to flag Australia as being excluded from the ranking.

 

Cheers,

Owen 🙂


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

@OwenAuger 

You are genius, thank you for helping this community.

Thanks so much Owen - your solution was great and gave me the result I was after!

 

Cheers again,

Megan

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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