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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Antmkjr
Post Patron
Post Patron

RANKX how to exclude certain rows from the context

AnuTomy_0-1653467639687.png

I am applying the below RANKX formula, 

Rank = RANKX(ALL('Table'[Continent]), CALCULATE(SUM('Table'[Sales]),ALLEXCEPT('Table','Table'[Continent])))
To get a Rank based on Continent.
 
I want to exclude certain countries, say France in this example, how to restructure the formula for this.

India1001Asia
Pakistan501Asia
China901Asia
Australia852Australia
France703Europe
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Antmkjr ,

 

Please check the formula.

Column = 
VAR rank_ =
    RANKX (
        'Table',
        CALCULATE (
            SUM ( 'Table'[Sales] ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[Continent] = EARLIER ( 'Table'[Continent] )
                    && 'Table'[Country] <> "France"
            )
        ),
        ,
        DESC,
        DENSE
    )
RETURN
    IF ( 'Table'[Country] = "France", BLANK (), rank_ )

vjaywmsft_0-1653979467055.png

 

Best Regards,

Jay

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Hi @Antmkjr ,

 

Please check the formula.

Column = 
VAR rank_ =
    RANKX (
        'Table',
        CALCULATE (
            SUM ( 'Table'[Sales] ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[Continent] = EARLIER ( 'Table'[Continent] )
                    && 'Table'[Country] <> "France"
            )
        ),
        ,
        DESC,
        DENSE
    )
RETURN
    IF ( 'Table'[Country] = "France", BLANK (), rank_ )

vjaywmsft_0-1653979467055.png

 

Best Regards,

Jay

ribisht17
Super User
Super User

@Antmkjr 

 

First >>

I can remove Sales from the context itself whenever I have France, In my case, it is "d"

Column = RANKX(FILTER( all(Sheet3),Sheet3[Category]=EARLIER(Sheet3[Category]) ),(IF(Sheet3[Sub Category]="d","",Sheet3[Sales])),,ASC,Dense)
 
By doing this I am ensuring that it will come at the bottom of my Rankings within a Category(NULL)
ribisht17_0-1653473650532.png

 

 

New Rank = IF(Sheet3[Sub Category]="d",0,Sheet3[Column])

 

ribisht17_1-1653474004770.png

 

 

You can exclude these 0s in the main dashboard as needed, also Ranking will not affect, it will just exclude d/France

 

Regards,

Ritesh

Antmkjr
Post Patron
Post Patron

Yes exactly

Antmkjr
Post Patron
Post Patron

Yes excatly

@Antmkjr 
Please try

Rank =
RANKX (
    ALL ( 'Table'[Continent] ),
    CALCULATE (
        SUMX (
            CALCULATETABLE (
                FILTER ( 'Table', NOT ( 'Table'[Country] IN { "India", "China" } ) ),
                ALLEXCEPT ( 'Table', 'Table'[Continent] )
            ),
            'Table'[Sales]
        )
    )
)
tamerj1
Super User
Super User

HI @Antmkjr 
Please try

Rank =
RANKX (
    FILTER (
        ALL ( 'Table'[Continent] ),
        CALCULATE ( VALUES ( 'Table'[Country] ) ) <> "France"
    ),
    CALCULATE ( SUM ( 'Table'[Sales] ), ALLEXCEPT ( 'Table', 'Table'[Continent] ) )
)

AnuTomy_0-1653468929414.png

It is wrongly calculating Rank of France here as 2, as I mentioned, I want to exclude France from this Ranking.

@Antmkjr 
Just to properly understand your rquirement. If we exclude India and China for example, then Asia will be ranked 3? Is this what you want?

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.