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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Antmkjr
Helper V
Helper V

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
v-jayw-msft
Community Support
Community Support

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

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

8 REPLIES 8
v-jayw-msft
Community Support
Community Support

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

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
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
Helper V
Helper V

Yes exactly

Antmkjr
Helper V
Helper V

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors