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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request 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

Click here to schedule a short Teams meeting to discuss your question.

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

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.