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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

TOPN for Ranking the top 3 elements

Hi, 

 

I've been using TOPN to create a Ranking that looks like this: 

Caesarul_1-1675846293207.png
Caesarul_0-1675846275539.png

 

Caesarul_2-1675846316776.png

 

The measures I used are: 

 

For Country Name: 

_1st Place =
MAXX (
    TOPN (
        1,
        SUMMARIZE (
            'GSW Active',
            'GSW Active'[Country],
            "Sum", [_Total Points]
        ),
        [Sum], DESC
    ),
    [Country]
)

For Country Flag: 
_1st Place Flag =
MAXX (
    TOPN (
        1,
        SUMMARIZE (
            'GSW Active',
            'GSW Active'[Wave Flags],
            "Sum", [_Total Points]
        ),
        [Sum], DESC
    ),
    [Wave Flags]
)


Everything works wonders for 2022 as you see above... but when I use the slicer to filter a different year/month. It's all going crazy. 
Caesarul_3-1675846517228.png
Caesarul_4-1675846527655.png
Caesarul_6-1675846558081.png

 

Do I need to add anything to these measures? 
 
The table is: 
Country/Month/Points/FlagURL

[_Total Points] = SUM of [Points]
Month is a 1st of each month - year date. 
In the slicer I use the same field and the yierarchy for year and month. 
 
Any ideas what I'm doing wrong? 
 
Thank you!
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Found a measure that works in this thread: https://community.powerbi.com/t5/Desktop/Top-Salesperson-displayed-in-a-card/m-p/598439 

Need to see if I can add another criteria of ranking to make it error proof (in case there are equal points in the first places). Please let me know if I can add anything to make this happen. 

_Top country =
VAR temp_table =
    SUMMARIZE (
        ALL ( 'GSW Active'[Country] ),
        'GSW Active'[Country],
        "SalesTotalValue", SUM ( 'GSW Active'[Total Points] )
    )
RETURN
    CALCULATE (
        MAX ( 'GSW Active'[Country] ),
        FILTER (
            ADDCOLUMNS ( temp_table, "Rank", RANKX ( temp_table, [SalesTotalValue] ) ),
            [Rank] = 1
        )
    )

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Found a measure that works in this thread: https://community.powerbi.com/t5/Desktop/Top-Salesperson-displayed-in-a-card/m-p/598439 

Need to see if I can add another criteria of ranking to make it error proof (in case there are equal points in the first places). Please let me know if I can add anything to make this happen. 

_Top country =
VAR temp_table =
    SUMMARIZE (
        ALL ( 'GSW Active'[Country] ),
        'GSW Active'[Country],
        "SalesTotalValue", SUM ( 'GSW Active'[Total Points] )
    )
RETURN
    CALCULATE (
        MAX ( 'GSW Active'[Country] ),
        FILTER (
            ADDCOLUMNS ( temp_table, "Rank", RANKX ( temp_table, [SalesTotalValue] ) ),
            [Rank] = 1
        )
    )
Anonymous
Not applicable

Tried to simplify things: 

Made a new page, where I added the leaderboard again and the top 3 countries and I have the same result, no matter what I try... works well for 2022 for some reason (maybe coincidence?) and then it goes wrong for 2021 and 2023. 

Filter 2022: 

Caesarul_0-1675881220652.png

Filter 2021:

Caesarul_1-1675881324610.png

 

I'm totally out of ideas... never thought that ranking and displaying a top value can be such a hard thing in a Business Intelligence tool... 

Please help! 

AilleryO
Memorable Member
Memorable Member

Hi,

 

Can you give us more information about your model (tables and relations). 

For example to help you we need to know where the year you are using to filter is coming from ?

Which table holds it ? And what are the relationship between this table and the others ?

Let us know so we might be able to help, but It do think it comes from a relationship problem.

Anonymous
Not applicable

hi @AilleryO

 

They are all in the same table: 

_Total Points = CALCULATE(SUM([Total Points]))

 

Country / Month / Total Points / Flag URL 

Caesarul_0-1675860932802.png

Caesarul_1-1675860984149.png


The slicers are the "Month" Column

Caesarul_2-1675861165015.pngCaesarul_3-1675861183898.png

 

 




Please let me know your thoughts. Thank you!

 

 



Anonymous
Not applicable

I tried using the Filters Panel as well: 

 

Caesarul_0-1675848738879.pngCaesarul_1-1675848758279.png

Caesarul_2-1675848771906.png

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.