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
powerbirino2
Regular Visitor

TOP 10 across multiple tables?

Hi.

 

I want to show top 5 countries by sales but I don't how I can do this. This is my database design.

 

powerbi.png

 

 I currently have achieved a matrix that shows all country-sales like this:

 

COUNTRYSALES
Spain4.000.000
France3.500.000
etc.etc.

 

So, how could I show only top 5 countries by their sales?

I worked on another project where I used this function:

RANKX(
           ALLSELECTED(Table[Column]);
           [SumOfSmth];;
           0;
           Dense
)

 

but it was "to do a top" on one table, not across many tables Smiley Frustrated

 

Thank you!

1 ACCEPTED SOLUTION
v-micsh-msft
Employee
Employee

Hi powerbirino2,

 

I agree to most of the points posted by ankitpatira, but I don’t think adjust the Visual could make it to only show 5 tops. What I did to achieve that is through the following ways:

  1. Add a visual level filter to filter the top 5 countries, based on the sales;
  2. Create a new table which only returns the top 5 country;

To have both ways work, we need to configure the relationship of the three table, to have Cross filter direction set to both.

For adding Visual Level Filter, see the image, Under Power BI Desktop Report view, when Visual selected, choose the country name and the sales as selected column, then under Filters, there would be country and sales available to configure, the following is an example I created with some testing data:

1.PNG

 

Under the same testing data, to create a new table with only the top 5 country, under Power BI desktop, select Modeling->New table, and enter the following formula:

Top5 = topn(
      5,
      SUMMARIZE(
           sheet3, 
           Sheet3[Country], 
           "sales", 
           sumx(sheet1, Sheet1[Sales])
        ),
     [sales],
     DESC)

 

See:

3.PNG

Let me know if those would work for you.

If any further help needed, please feel free to post back.

Regards

View solution in original post

2 REPLIES 2
v-micsh-msft
Employee
Employee

Hi powerbirino2,

 

I agree to most of the points posted by ankitpatira, but I don’t think adjust the Visual could make it to only show 5 tops. What I did to achieve that is through the following ways:

  1. Add a visual level filter to filter the top 5 countries, based on the sales;
  2. Create a new table which only returns the top 5 country;

To have both ways work, we need to configure the relationship of the three table, to have Cross filter direction set to both.

For adding Visual Level Filter, see the image, Under Power BI Desktop Report view, when Visual selected, choose the country name and the sales as selected column, then under Filters, there would be country and sales available to configure, the following is an example I created with some testing data:

1.PNG

 

Under the same testing data, to create a new table with only the top 5 country, under Power BI desktop, select Modeling->New table, and enter the following formula:

Top5 = topn(
      5,
      SUMMARIZE(
           sheet3, 
           Sheet3[Country], 
           "sales", 
           sumx(sheet1, Sheet1[Sales])
        ),
     [sales],
     DESC)

 

See:

3.PNG

Let me know if those would work for you.

If any further help needed, please feel free to post back.

Regards

ankitpatira
Community Champion
Community Champion

@powerbirino2 if you have the relationship established in power bi desktop as shown in picture then you don't need to use any measures. Simply use any visual for example bar chart and use country name and sales columns and it will automatically show you sales by countries. To get top 5, if you've used bar chart then on top right hand corner click ellipses (three dots) and use Sort By option to sort by sales. This will show you top sales and by countries and you can adjust the size of visual so that only top 5 countries are visible.

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.