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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
cwilson
New Member

Pie Chart of Top 8 with Other Filtered by Product and Date

I'm trying to build a pie chart by filtering a larger table that gives me sum of a selected product ranked to the top 8 countries with the  remainder in "other." The full table includes all countries, about 20 different products going back monthly about 20 years and I am trying to create a pie chart of export volumes totaled by filtered products for a selected month or period of time. Currently I'm manually grouping them each month but is there a way to dynamically rank each country based on the filters applied and show the top 8 plus the rest as Other?

 

 

 

cwilson_0-1665590171771.png

1 ACCEPTED SOLUTION
v-easonf-msft
Community Support
Community Support

Hi, @cwilson 

Please try follow steps:

1. build a calculated table like:

Pseudo Table = 
UNION(
    DISTINCT('Table'[Country]),
    DATATABLE("Country",STRING,{{"Others"}})
)

veasonfmsft_0-1665653259681.png

2. Then try measure like:

Top 2 Sum Sales = 
VAR TopNSelected = 2
VAR TopCountryTable = 
    TOPN(
        TopNSelected,
        ALLSELECTED('Pseudo Table'),
        [Value]
    )
VAR TopCountrySales =
    CALCULATE(
         [Value],
        KEEPFILTERS( TopCountryTable  )
    )
VAR OtherSales = 
    CALCULATE(
         [Value],
        ALLSELECTED('Pseudo Table')
    ) - 
    CALCULATE(
         [Value],
        TopCountryTable 
    )
VAR CurrentProd = SELECTEDVALUE('Pseudo Table'[Country])
RETURN
    IF(
        CurrentProd <> "Others",
        TopCountrySales,
        OtherSales
    )

veasonfmsft_2-1665653481074.png

Please refer to  the following tutorial for more details.

https://goodly.co.in/top-n-and-others-power-bi/ 

 

Best Regards,
Community Support Team _ Eason

View solution in original post

1 REPLY 1
v-easonf-msft
Community Support
Community Support

Hi, @cwilson 

Please try follow steps:

1. build a calculated table like:

Pseudo Table = 
UNION(
    DISTINCT('Table'[Country]),
    DATATABLE("Country",STRING,{{"Others"}})
)

veasonfmsft_0-1665653259681.png

2. Then try measure like:

Top 2 Sum Sales = 
VAR TopNSelected = 2
VAR TopCountryTable = 
    TOPN(
        TopNSelected,
        ALLSELECTED('Pseudo Table'),
        [Value]
    )
VAR TopCountrySales =
    CALCULATE(
         [Value],
        KEEPFILTERS( TopCountryTable  )
    )
VAR OtherSales = 
    CALCULATE(
         [Value],
        ALLSELECTED('Pseudo Table')
    ) - 
    CALCULATE(
         [Value],
        TopCountryTable 
    )
VAR CurrentProd = SELECTEDVALUE('Pseudo Table'[Country])
RETURN
    IF(
        CurrentProd <> "Others",
        TopCountrySales,
        OtherSales
    )

veasonfmsft_2-1665653481074.png

Please refer to  the following tutorial for more details.

https://goodly.co.in/top-n-and-others-power-bi/ 

 

Best Regards,
Community Support Team _ Eason

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.