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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
AndreasHermle
Regular Visitor

Retrieve Top5 Countries Total from a table visual and have it displayed in a card visual?

Dear Experts: 

 

I have got a table visual as follows: 

It shows the Top 5 Countries by Category Sales. along with a Ranking Column. It works just fine.
Top5Countries-By-CategorySales.png

The two measures Top5Countries and Ranking are as follows (please see below). They work just fine everything is ok.
Now here comes my question: How can I retrieve The Total Sales as depicted in the Table Visual (142,171,598 €) and have that value displayed in a card visual. 

 

Help is very much appreciated. Thank you very much in advance. Regards, Andreas
 

Top5Countries =
Var CountryRank =
RANKX(
    FILTER(
        ALLSELECTED(DimCtry),
        CALCULATE(
            [Total Sales],
            DimProd[CategoryID] = SELECTEDVALUE(DimCat[CategoryID])  // Ensure ranking respects category context
        )
    ),
    CALCULATE([Total Sales]),
    ,
    DESC,
    DENSE
)
RETURN
IF (CountryRank <= 5, [Total Sales], BLANK())

Ranking =
VAR RankValue =
    RANKX(
        FILTER(
            ALLSELECTED(DimCtry),
            CALCULATE(
                [Total Sales],
                DimProd[CategoryID] IN VALUES(DimCat[CategoryID])
            )
        ),
        [Total Sales],
        ,
        DESC,
        DENSE
    )
RETURN
    IF(RankValue <= 5, RankValue, BLANK()) // Only keep ranks 1-5, ignore others
1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

In this case, one of ways is using WINDOW and RANK DAX functions in measures.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1747070177415.png

 

WINDOW function (DAX) - DAX | Microsoft Learn

RANK function (DAX) - DAX | Microsoft Learn

 

Jihwan_Kim_0-1747070165601.png

 

Total sales: = 
SUM(sales[sales])

 

Top 5 countries within category: = 
VAR _topn =
    WINDOW (
        1,
        ABS,
        5,
        ABS,
        SUMMARIZE (
            ALL ( sales ),
            category[category],
            country[country]
        ),
        ORDERBY ( [Total sales:], DESC ),
        ,
        PARTITIONBY ( category[category] )
    )
RETURN
    CALCULATE (
        [Total sales:],
        KEEPFILTERS ( _topn )
    )

 

Ranking: = 
IF (
    [Top 5 countries within category:],
    RANK (
        SKIP,
        SUMMARIZE (
            ALL ( sales ),
            category[category],
            country[country]
        ),
        ORDERBY ( [Total sales:], DESC ),
        ,
        PARTITIONBY ( category[category] )
    )
)

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

View solution in original post

3 REPLIES 3
AndreasHermle
Regular Visitor

Wow Kim, 
I am deeply impressed by your expertise. That's the way I wanted it. Thank you very much for your great help. I really appreciate it. 
Best Regards, Andreas

v-kpoloju-msft
Community Support
Community Support

Hi @AndreasHermle,

May i know has your issue been resolved? If the response provided by the community member @Jihwan_Kim, addressed your query, could you please confirm? It helps us ensure that the solutions provided are effective and beneficial for everyone.

If yes, kindly accept the useful reply as a solution and give us Kudos. It would be appreciated.

Thank you for your understanding!

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

In this case, one of ways is using WINDOW and RANK DAX functions in measures.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1747070177415.png

 

WINDOW function (DAX) - DAX | Microsoft Learn

RANK function (DAX) - DAX | Microsoft Learn

 

Jihwan_Kim_0-1747070165601.png

 

Total sales: = 
SUM(sales[sales])

 

Top 5 countries within category: = 
VAR _topn =
    WINDOW (
        1,
        ABS,
        5,
        ABS,
        SUMMARIZE (
            ALL ( sales ),
            category[category],
            country[country]
        ),
        ORDERBY ( [Total sales:], DESC ),
        ,
        PARTITIONBY ( category[category] )
    )
RETURN
    CALCULATE (
        [Total sales:],
        KEEPFILTERS ( _topn )
    )

 

Ranking: = 
IF (
    [Top 5 countries within category:],
    RANK (
        SKIP,
        SUMMARIZE (
            ALL ( sales ),
            category[category],
            country[country]
        ),
        ORDERBY ( [Total sales:], DESC ),
        ,
        PARTITIONBY ( category[category] )
    )
)

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.