Forum Discussion

AndreasHermle's avatar
AndreasHermle
Regular Visitor
1 year ago
Solved

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. The two measures Top5Countries and R...
  • Jihwan_Kim's avatar
    1 year ago

    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.

     

     

    WINDOW function (DAX) - DAX | Microsoft Learn

    RANK function (DAX) - DAX | Microsoft Learn

     

     

    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] )
        )
    )