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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Creating TopN with two levels

I have a table with Continent, Countries and product. Sample table below

 

Continent   Country   Product

Asia             India       A

Asia             China      B

Asia             India       C

Europe        Germany D

Europe        France     E

Europe        Denmark F

 

I would like to get the Top 10 countries per Continent in a Table. I have searched online, but most of the TopN and Rank formula are for just 1 level of TopN. Any help would be really appreciated.

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi there,

 

Here is how I would do it - I assume you're ranking using a measure.

Change [Your Measure] to the measure used for ranking and YourTable to the appropriate table name.

 

 

Your Measure for Top 10 Countries Per Continent = 
CALCULATE (
    [Your Measure],
    KEEPFILTERS (
        GENERATE (
            VALUES ( YourTable[Continent] ),
            TOPN ( 10, ALL ( YourTable[Country] ), [Your Measure] )
        )
    )
)

 

You could also do it this way if your measure can be summed by Continent:

 

Your Measure for Top 10 Countries Per Continent v2 =
SUMX (
    VALUES ( YourTable[Continent] ),
    CALCULATE (
        [Your Measure],
        TOPN ( 10, ALL ( YourTable[Country] ), [Your Measure] ),
        VALUES ( YourTable[Country] )
    )
)

 

If you just want to display the Countries but not the measure itself, you can use a Visual Level Filter on this measure to nonblank.


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

2 REPLIES 2
OwenAuger
Super User
Super User

Hi there,

 

Here is how I would do it - I assume you're ranking using a measure.

Change [Your Measure] to the measure used for ranking and YourTable to the appropriate table name.

 

 

Your Measure for Top 10 Countries Per Continent = 
CALCULATE (
    [Your Measure],
    KEEPFILTERS (
        GENERATE (
            VALUES ( YourTable[Continent] ),
            TOPN ( 10, ALL ( YourTable[Country] ), [Your Measure] )
        )
    )
)

 

You could also do it this way if your measure can be summed by Continent:

 

Your Measure for Top 10 Countries Per Continent v2 =
SUMX (
    VALUES ( YourTable[Continent] ),
    CALCULATE (
        [Your Measure],
        TOPN ( 10, ALL ( YourTable[Country] ), [Your Measure] ),
        VALUES ( YourTable[Country] )
    )
)

 

If you just want to display the Countries but not the measure itself, you can use a Visual Level Filter on this measure to nonblank.


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn
Anonymous
Not applicable

This is wonderful! Works perfectly! Thanks Man Happy

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.