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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

TOP 10 countries using DAX code

Hello Experts,
I want to help me to write the DAX code to show only the TOP 10 Countries based on Revenue.

 

xxxx.png

2 ACCEPTED SOLUTIONS

@Anonymous it should work :))

SpartaBI_0-1653218254374.png

What is [Att_Value1]? Is that a column or a measure?

View solution in original post

@Anonymous no worries 🙂
This is for the scenario where the total is for all (just change it to your names and 10 instead of 3):

 

 

Top 3 Countries By Sales = 
VAR _countries = TOPN(3, ALLSELECTED(Customer[Country]),[Sales Amount])
RETURN
    IF(
        ISINSCOPE(Customer[Country]),
        CALCULATE(
            [Sales Amount],
            KEEPFILTERS(_countries)
        ),
        [Sales Amount]
    )

 

 

SpartaBI_0-1653219251405.png2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

View solution in original post

7 REPLIES 7
SpartaBI
Community Champion
Community Champion

@Anonymous 

 

Top 10 Countries By Revenues = 
VAR _top10_countries = TOPN(10, ALLSELECTED('Table'[Country]),[Revenues Measure])
RETURN
    CALCULATE(
        [Sales Amount],
        KEEPFILTERS(_top10_countries)
    )

 

 


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

Anonymous
Not applicable

@SpartaBI 
its dose not worked,
see the right visual which I used a filter pane to show  the top 10 countries. 
In your code dax which is in left visual it dose give the top 10 countries and the numbers are nor correct.

 

xcxc.png

@Anonymous what is the column you use in the matrix for country, and what ia the base measure?

Anonymous
Not applicable

its same, I know you sae different name in code and visual, but its same the coulm and measure. 

@SpartaBI 

@Anonymous it should work :))

SpartaBI_0-1653218254374.png

What is [Att_Value1]? Is that a column or a measure?

Anonymous
Not applicable

Its worked. So Sorry I had a mistake. I will Accept your solurtions.

I have another Question: 
If I want  to show top 10 countries and show me the grand total of each country  out of all countries ( I dont want to give  the grand total  of Top 10 countries  only). 

@Anonymous no worries 🙂
This is for the scenario where the total is for all (just change it to your names and 10 instead of 3):

 

 

Top 3 Countries By Sales = 
VAR _countries = TOPN(3, ALLSELECTED(Customer[Country]),[Sales Amount])
RETURN
    IF(
        ISINSCOPE(Customer[Country]),
        CALCULATE(
            [Sales Amount],
            KEEPFILTERS(_countries)
        ),
        [Sales Amount]
    )

 

 

SpartaBI_0-1653219251405.png2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.