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
Anonymous
Not applicable

Ranking a Country within Continents with data at a City level using a lookup table.

Hey, trying to solve this one for a while now. Lots of solutions that come close but don't exactly do what I need it to.

 

I have a data table "city data" (Month, City, Total Spend, Park Spend) and a lookup table "lookup" (City, Country, Continent) connected on City.

 

My goal is to have a drop down for Country that will update a card visual (not table) with the that Country's rank within the Continent based on a measure - let's say Park Spend % = Sum of Park Spend / Sum of Total Spend. This measure can change, I will use a SWITCH in my ranking solution to allow the basis metric/measure to be dynamic. For the sake of this problem let's assume I have a measure Park Spend %.

 

I have screenshots and a sample of the tables and goal below.

 

Any assistance will be appreciated!

 

datadata

lookuplookup

goalgoal

 

city data

MonthCityTotal SpendPark Spend
1A91.9642.46
1B77.0445.64
1C80.3549.78
1D79.1235.73
1E98.645.97
2A90.9345.59
2B99.147.54
2C93.6243.26
2D92.0643.99
2D78.5146.31
3A99.1546.42
3B86.1738.78
3C86.9639.27
3D78.9839.54
3E90.8135.36
4A75.547.81
4B88.6237.74
4C75.3837.78
4D98.1442.25
4E82.8138.54

 

lookup

CityCountryContinent
AUSNorth America
BUSNorth America
CCanadaNorth America
DCanadaNorth America
EUKEurope
1 ACCEPTED SOLUTION
littlemojopuppy
Community Champion
Community Champion

Hi @Anonymous 

 

Try this...

Country Ranking = 
VAR CountriesInContinent =
    CALCULATETABLE(
        VALUES(Geography[Country]),
        FILTER(
            ALL(Geography),
            Geography[Continent] = SELECTEDVALUE(Geography[Continent])
        )
    )
RETURN

RANKX(
    CountriesInContinent,
    [Park Spend %],
    [Park Spend %],
    DESC,
    Skip
)

 

Produces these results

littlemojopuppy_0-1646527821700.png

The matrix was to make sure each country was calculating correctly within its continent...

 

Hope this helps!

View solution in original post

9 REPLIES 9
Whitewater100
Solution Sage
Solution Sage

Anonymous
Not applicable

When I select UK, country rank returns 3, while it should return 1 since UK ranks 1 in Europe. Like I mentioned, I would like to see the Country Rank within it's Continent on the card.

aqr_0-1646563027706.png

 

@Anonymous please refer to the solution I posted an hour before @Whitewater100

littlemojopuppy_0-1646567470603.png

 

Anonymous
Not applicable

Yes, I saw your response and am evaluating it.

littlemojopuppy
Community Champion
Community Champion

Hi @Anonymous 

 

Try this...

Country Ranking = 
VAR CountriesInContinent =
    CALCULATETABLE(
        VALUES(Geography[Country]),
        FILTER(
            ALL(Geography),
            Geography[Continent] = SELECTEDVALUE(Geography[Continent])
        )
    )
RETURN

RANKX(
    CountriesInContinent,
    [Park Spend %],
    [Park Spend %],
    DESC,
    Skip
)

 

Produces these results

littlemojopuppy_0-1646527821700.png

The matrix was to make sure each country was calculating correctly within its continent...

 

Hope this helps!

Anonymous
Not applicable

@littlemojopuppy  Thanks for your response it does what I asked for and I can see has already been marked as the solution.

 

However, in my actual dataset, applying any date slicer from a connected calendar table causes the rank to  be funny when in a card but populates correctly against the country in a table. No idea why that would happen. Even if I select all on my date slicer, that is nothing is excluded, my rank in the card is wrong, But if I don't engage the slicer at all - it works fine. Do you have any thoughts?

@Anonymous how are you creating the relationship between the date table and this table?  Because the sample data you shared only has month number (and no year).

 

Could you share your pbix?

Hi littlemojopuppy:

When I saw this quesition yesterday, no one had replied on it. I went to work on it and posted my answer as soon as I finished,  still without seeing your answer until today. 

 

Sorry for any confusion.

 

When did you answer and when did I, as I did my answer fairly quickly after seeing the question?

 

@Whitewater100 you posted your response an hour after I did.  I've noticed you doing this on multiple posts in the last couple weeks, both to me and to others.  There's an expectation of etiquette in the forum, where we try not to overwhelm the users with numerous responses.  Because all it does is create confusion.  It would be appreciated if you followed etiquette.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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