Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
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
Solved! Go to Solution.
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
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
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
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:
Create a DAX column to assign color hex codes for each slice:
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) )
Bring this color column into your pie chart:
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.
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.
User | Count |
---|---|
81 | |
75 | |
74 | |
42 | |
36 |
User | Count |
---|---|
114 | |
56 | |
51 | |
42 | |
42 |