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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
matheus_peppers
Frequent Visitor

How to make RANKX ignore column rows containing certain strings?

Hello, how are you?

I am creating a RANKX function, where it brings me the ranking of cities that had the most ad reach, however, I want in this function, to make RANKX not consider the lines that are written a certain string, such as "Unidentified City", as it is in my case.

 

Does anyone know how I can achieve this?

I have tried the following DAX formula and several others, but it is not working:

 

FB - Ranking Reach (cities) v2 =
RANKX (
    ALL ( dFacebook_AdSets[City] ),
    [FB - TOTAL Reach],
    NOT(
        FILTER(dFacebook_AdSets,dFacebook_AdSets[City] IN {"Unidentified City in Vale do Paraíba"}
    )
)
)

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

You could try something like

FB Ranking =
VAR CitiesToIgnore = { "Unidentified City in Vale do Paraíba" }
VAR CitiesToRank =
    EXCEPT ( ALL ( dFacebook_AdSets[City] ), CitiesToIgnore )
RETURN
    RANKX ( CitiesToRank, [FB - TOTAL Reach] )

Just add more entries into the CitiesToIgnore variable

View solution in original post

3 REPLIES 3
johnt75
Super User
Super User

You could try something like

FB Ranking =
VAR CitiesToIgnore = { "Unidentified City in Vale do Paraíba" }
VAR CitiesToRank =
    EXCEPT ( ALL ( dFacebook_AdSets[City] ), CitiesToIgnore )
RETURN
    RANKX ( CitiesToRank, [FB - TOTAL Reach] )

Just add more entries into the CitiesToIgnore variable

Could you explain me the logic behind this function you did? Sorry for the ignorant or even layman question, it's because I am new to DAX and want to master this language.

The CitiesToRank variable will contain all the cities in your data except the ones you put into the CitiesToIgnore variable, those will be filtered out. The RANKX then iterates over the CitiesToRank variable, so only the cities which have not been excluded will be considered and given a ranking.

If you're new to DAX an haven't done so already, check out www.sqlbi.com. Everything on there is extremely helpful, and their Mastering DAX course is well worth taking if you can.

Helpful resources

Announcements
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.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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