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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
frost789
Frequent Visitor

How to apply conditional formatting to multiple pies in a pie chart?

Is it possible to accomplish this in a pie chart?

Pass pie is always gray (#e6e6e6)

 

If Fail percentage is <=8%, the Fail pie should be green

If Fail percentage is >8% and <=10%, the Fail pie should be yellow

If Fail percentage is > 10%, the Fail pie should be red

 

If Withdraw percentage is <=8%, the Withdraw pie should be green

If Withdraw percentage is >8% and <=10%, the Withdraw pie should be yellow

If Withdraw percentage is > 10%, the Withdraw pie should be red

 

The Power BI file is here

https://filebin.net/k73pbolb3kmvgolp/PieChartConditionalFormatting.pbix

1 ACCEPTED SOLUTION
kushanNa
Solution Sage
Solution Sage

Hi @frost789 

 

try to follow following steps 

1.first create a cluster column chart 
2. add PFW column as X axis 

3. create the following measure and and it into the y axis 

Student Count Percentage (of Total) = 
VAR CurrentCount = COUNTROWS('Dup Data') // Count of rows for current slice
VAR TotalCount = CALCULATE(COUNTROWS('Dup Data'), REMOVEFILTERS('Dup Data'[PFW])) // Total count across all PFW values
RETURN
    DIVIDE(CurrentCount, TotalCount, 0)

4.Create the following measure as well 

Universal Slice Color By Percentage = 
VAR CurrentSlicePercentage = [Student Count Percentage (of Total)] // % for current slice
VAR Category = SELECTEDVALUE('Dup Data'[PFW]) // "Pass", "Fail", or "Withdraw"

RETURN
    SWITCH(TRUE(),
        Category = "Pass", "#e6e6e6", // Always gray for Pass
        
        Category = "Fail" && CurrentSlicePercentage <= 0.08, "Green",
        Category = "Fail" && CurrentSlicePercentage > 0.08 && CurrentSlicePercentage <= 0.10, "Yellow",
        Category = "Fail" && CurrentSlicePercentage > 0.10, "Red",

        Category = "Withdraw" && CurrentSlicePercentage <= 0.08, "Green",
        Category = "Withdraw" && CurrentSlicePercentage > 0.08 && CurrentSlicePercentage <= 0.10, "Yellow",
        Category = "Withdraw" && CurrentSlicePercentage > 0.10, "Red",

        "Silver" // Default color for unexpected cases
    )


5. now go to bar chart column colors and keep categories - All > click on fx 

6. drop down format style and and select field values 

7. drop down fileds and pick Universal Slice Color By Percentage measure 

8. now click on pie chart visual and convert the column chart to a pie chart 

that's it you should get the result you need 

 

kushanNa_0-1749570387562.png

 

View solution in original post

7 REPLIES 7
kushanNa
Solution Sage
Solution Sage

Hi @frost789 

 

try to follow following steps 

1.first create a cluster column chart 
2. add PFW column as X axis 

3. create the following measure and and it into the y axis 

Student Count Percentage (of Total) = 
VAR CurrentCount = COUNTROWS('Dup Data') // Count of rows for current slice
VAR TotalCount = CALCULATE(COUNTROWS('Dup Data'), REMOVEFILTERS('Dup Data'[PFW])) // Total count across all PFW values
RETURN
    DIVIDE(CurrentCount, TotalCount, 0)

4.Create the following measure as well 

Universal Slice Color By Percentage = 
VAR CurrentSlicePercentage = [Student Count Percentage (of Total)] // % for current slice
VAR Category = SELECTEDVALUE('Dup Data'[PFW]) // "Pass", "Fail", or "Withdraw"

RETURN
    SWITCH(TRUE(),
        Category = "Pass", "#e6e6e6", // Always gray for Pass
        
        Category = "Fail" && CurrentSlicePercentage <= 0.08, "Green",
        Category = "Fail" && CurrentSlicePercentage > 0.08 && CurrentSlicePercentage <= 0.10, "Yellow",
        Category = "Fail" && CurrentSlicePercentage > 0.10, "Red",

        Category = "Withdraw" && CurrentSlicePercentage <= 0.08, "Green",
        Category = "Withdraw" && CurrentSlicePercentage > 0.08 && CurrentSlicePercentage <= 0.10, "Yellow",
        Category = "Withdraw" && CurrentSlicePercentage > 0.10, "Red",

        "Silver" // Default color for unexpected cases
    )


5. now go to bar chart column colors and keep categories - All > click on fx 

6. drop down format style and and select field values 

7. drop down fileds and pick Universal Slice Color By Percentage measure 

8. now click on pie chart visual and convert the column chart to a pie chart 

that's it you should get the result you need 

 

kushanNa_0-1749570387562.png

 

What should I do if I'd like to change the display value to the number of students instead of a point decimal value?

hi @frost789 

 

use your mesure student count as values

 

i forgot you do not actually need to overlay visuals 

 

kushanNa_0-1749605583439.png

 

 

 

 

 

burakkaragoz
Community Champion
Community Champion

Hi @frost789 ,

 

Great question! While Power BI doesn’t support true conditional formatting directly in pie charts like it does in bar or table visuals, you can still achieve dynamic color assignment using a DAX column and manual color formatting.

Here’s how you can do it:

  1. Create a DAX column to assign color hex codes for each slice:

    • For example, for the Fail pie:
    dax
     
    Fail Pie Color =
    SWITCH(
      TRUE(),
      [Fail %] <= 0.08, "#27ae60",         // green
      [Fail %] > 0.08 && [Fail %] <= 0.10, "#f4d03f", // yellow
      [Fail %] > 0.10, "#e74c3c",          // red
      "#e6e6e6"                            // default (gray)
    )
    • Do the same for Withdraw pies, adjusting the logic for [Withdraw %].
  2. Bring this color column into your pie chart:

    • Add your “Fail Pie Color” field into the Legend or Details.
    • In the “Format” pane > “Slices” > manually set the color for each legend value using the hex code you defined.
  3. For the Pass pie, set the color to always #e6e6e6 (gray).

Note:
Pie chart conditional formatting in Power BI is not fully automatic—you must assign the color for each legend value, but using a dynamic color column makes this manageable and ensures any new values are easy to assign.

If you want a step-by-step with your sample PBIX, let me know!

I'm not able to Add the “Fail Pie Color” field into the Legend or Details. Power BI says: "This field can't be used here because a non-measure field is required."

Would you please do a step-by-step with my sample PBIX. Thank you!

Hi @frost789,


For your follow-up: If you want to display the actual number of students in the chart (instead of a decimal or percentage), you just need to change the measure used for the value field in your chart.

  • Instead of using the “percentage” measure on the Y-axis or values field, use the count of students (for example, COUNT([StudentID]) or the relevant field representing student count).
  • If you want both number and percentage, you can create a tooltip or a custom label with both values via a DAX measure.

If you let me know your data structure (e.g., what column represents the student count), I can help you write the exact DAX formula!

Let me know if you need a step-by-step.

Of course, his reply doesn't make sense. While you can use a calculated column as a legend, it will not dynamically change the color of the slicers. What you will see are the values returned by the calculated column.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

May 2025 Monthly Update

Fabric Community Update - May 2025

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