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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Louis66
Resolver I
Resolver I

Pie chart for many years, country colors

Hello,

 

I have an Excel spreadsheet with the list of the 10 wealthiest people in the world, for each year. I also have their country. The problem : country colors are random in my pie chart... for example for the US, I would like the slice to be in red.

 

I created a table (HOME/ENTER DATA) with my list of countries (column A) AND colors (column B), then I "linked" the countries with my main table... nothing happens.

 

Regards,

 

Louis

2 ACCEPTED SOLUTIONS
johncolley
Solution Sage
Solution Sage

Hi @Louis66 , Depending on the number of countries in your list it may be easier just edit it in the visual settings: 

johncolley_0-1663212059387.png

 

View solution in original post

Hello John,

 

Thank you for your answer - unfortunately, I have many years to do, and sometimes rich people will be in Japan & USA, whereas they could be in China, Japan & USA the following year... so I need to link a list of countries (I have 16 countries) with different colors.

 

Louis

View solution in original post

4 REPLIES 4
johncolley
Solution Sage
Solution Sage

Hi @Louis66 , Depending on the number of countries in your list it may be easier just edit it in the visual settings: 

johncolley_0-1663212059387.png

 

Hello John,

 

Thank you for your answer - unfortunately, I have many years to do, and sometimes rich people will be in Japan & USA, whereas they could be in China, Japan & USA the following year... so I need to link a list of countries (I have 16 countries) with different colors.

 

Louis

Hi @Louis66 , If you have no years selected when first creating the pie you can choose an option for each and then when filtering to a specific year it will retain the colours.

 

Having said that you can follow the instructions provided by @m_alireza  which will work fine and will easier to maintain if your dataset continues to grow.

m_alireza
Solution Specialist
Solution Specialist

Hi @Louis66 , Power BI does not have conditional formatting options for a Pie Chart but I found this post that shows a way around it: 

https://community.powerbi.com/t5/Community-Blog/Power-BI-Conditional-formatting-the-Pie-Visual/ba-p/...

The post explains how you have to create a chart, apply the conditional formatting and then convert it to a pie chart as explained below:

First, create a stacked column chart with your values from the main table (I put Country and Count of Person's Name as I dont know what you exactly have in your data)

stacked chart pic.png

 


Create this measure (this will be used to apply the colour to the countries), where
Table A = your main table that contains the list of wealthy people
Table B = your table with the list of countries and colours:

 

colour = CALCULATE(MAX(TableB[colourcolumn]),FILTER('TableA',MAX('TableA'[countrycolumn])=ALLSELECTED(TableB[countrycolumn])))

 


Click on your chart, go to Format your Visual and expand Columns, find Colour and click on fx. In the pop up box, change the format style to Field Value and place your colour measure under field
formatting colours.png

 


cond formatting box.png




Once you do that, you should see the conditional formatting applied. Then all you have to do is convert the chart to the pie chart and you should see the colours you designated per country apply:
coloured chart.pngpie chart colour.png

Hope this helps. 

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors