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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

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
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.