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
KMcCarthy9
Helper IV
Helper IV

Conditional Formatting for % of Column Total - Not Working

I was able to achieve conditional formatting in a matrix by first creating the measure below:

% of Total Workorders =
VAR _FilterCount = COUNTROWS('workorder')
VAR _AllCount = CALCULATE(COUNTROWS(workorder),ALLSELECTED(workorder))

RETURN

DIVIDE(_FilterCount,_AllCount)

Then applied this measure to the conditional formatting by field value:
% of Total Workorder Color =
VAR _30DaysBL = IF(AND(SELECTEDVALUE(workorder[Backlog Timeframe])="Within 30 Days",SELECTEDVALUE(workorder[Backlog Status Group])="Backlog"),True,False)
VAR _30DaysCO = IF(AND(SELECTEDVALUE(workorder[Backlog Timeframe])="Within 30 Days",SELECTEDVALUE(workorder[Backlog Status Group])="Closeout"),True,False)
VAR _31DaysBL = IF(AND(SELECTEDVALUE(workorder[Backlog Timeframe])="31 - 60 Days",SELECTEDVALUE(workorder[Backlog Status Group])="Backlog"),True,False)
VAR _31DaysCO = IF(AND(SELECTEDVALUE(workorder[Backlog Timeframe])="31 - 60 Days",SELECTEDVALUE(workorder[Backlog Status Group])="Closeout"),True,False)
VAR _61DaysBL = IF(AND(SELECTEDVALUE(workorder[Backlog Timeframe])="61+ Days",SELECTEDVALUE(workorder[Backlog Status Group])="Backlog"),True,False)
VAR _61DaysCO = IF(AND(SELECTEDVALUE(workorder[Backlog Timeframe])="61+ Days",SELECTEDVALUE(workorder[Backlog Status Group])="Closeout"),True,False)

RETURN

SWITCH(
TRUE(),
_61DaysBL && [% of Total Workorders] <=.049, "#C6EFCE",--Green
_61DaysBL && [% of Total Workorders] >= .050,"#FFC7CE",--Red
_31DaysBL && [% of Total Workorders] <=.099, "#C6EFCE",
_31DaysBL && [% of Total Workorders] >= .100,"#FFC7CE",
_30DaysBL && [% of Total Workorders] >= .850,"#C6EFCE",
_30DaysBL && [% of Total Workorders] <=.849, "#FFC7CE",

_61DaysCO && [% of Total Workorders] <=.300, "#C6EFCE",
_61DaysCO && [% of Total Workorders] >= .319,"#FFC7CE",
_31DaysCO && [% of Total Workorders] <=.700, "#FFC7CE",
_31DaysCO && [% of Total Workorders] >= .719,"#C6EFCEE",
_30DaysCO && [% of Total Workorders] >= .719,"#C6EFCE",
_30DaysCO && [% of Total Workorders] <=.700, "#FFC7CE",
"#FFF000")--Yellow

This works correctly but gives the percentage for the entire visual, when I would really like to show it by % of column total. When I select "Show as % of CT" the conditional formatting does not change and is not correct. Is it possible to use a measure for conditional formatting while showing % of CT?
1 ACCEPTED SOLUTION

hi, @KMcCarthy9 

1. For your requirement, you want  "% of CT" in the matrix, you should use ALLSELECTED([Backlog Timeframe]) in formula like below:

% of Total Workorders = 
VAR _FilterCount = COUNTROWS('Backlog Trend Data')
VAR _AllCount = CALCULATE(COUNTROWS('Backlog Trend Data'),ALLSELECTED('Backlog Trend Data'[Backlog Timeframe - All Time]))

RETURN

DIVIDE(_FilterCount,_AllCount)

and you said it gives you the result of 100% in each cell.

So there should be a dim Backlog Timeframe table, please replace ALLSELECTED(workorder[Backlog Timeframe]) with it.

2. In this sample pbix, I find that there is a logic error in your formula:

% of Total Workorder Color = 
VAR _30DaysBL = IF(AND(SELECTEDVALUE('Backlog Trend Data'[Backlog Timeframe - All Time]) = "Within 30 Days",SELECTEDVALUE('Backlog Trend Data'[Workorder Category])="Backlog"),True,False)
VAR _30DaysCO = IF(AND(SELECTEDVALUE('Backlog Trend Data'[Backlog Timeframe - All Time]) = "Within 30 Days",SELECTEDVALUE('Backlog Trend Data'[Workorder Category])="Closeout"),True,False)
VAR _31DaysBL = IF(AND(SELECTEDVALUE('Backlog Trend Data'[Backlog Timeframe - All Time]) ="31 - 60 Days",SELECTEDVALUE('Backlog Trend Data'[Workorder Category])="Backlog"),True,False)
VAR _31DaysCO = IF(AND(SELECTEDVALUE('Backlog Trend Data'[Backlog Timeframe - All Time]) ="31 - 60 Days",SELECTEDVALUE('Backlog Trend Data'[Workorder Category])="Closeout"),True,False)
VAR _61DaysBL = IF(AND(SELECTEDVALUE('Backlog Trend Data'[Backlog Timeframe - All Time])="61+ Days",SELECTEDVALUE('Backlog Trend Data'[Workorder Category])="Backlog"),True,False)
VAR _61DaysCO = IF(AND(SELECTEDVALUE('Backlog Trend Data'[Backlog Timeframe - All Time]) ="61+ Days",SELECTEDVALUE('Backlog Trend Data'[Workorder Category])="Closeout"),True,False)

RETURN

SWITCH(
    TRUE(),
_61DaysBL && [% of Total Workorders] <=.049, "#C6EFCE",--Green
_61DaysBL && [% of Total Workorders] >= .050,"#FFC7CE",--Red
_31DaysBL && [% of Total Workorders] <=.099, "#C6EFCE",
_31DaysBL && [% of Total Workorders] >= .010,"#FFC7CE",
_30DaysBL && [% of Total Workorders] >= .850,"#C6EFCE",
_30DaysBL && [% of Total Workorders] <=.849, "#FFC7CE",

_61DaysCO && [% of Total Workorders] <=.300, "#C6EFCE",
_61DaysCO && [% of Total Workorders] >= .319,"#FFC7CE",
_31DaysCO && [% of Total Workorders] <=.700, "#FFC7CE",
_31DaysCO && [% of Total Workorders] >= .710,"#C6EFCEE",
_30DaysCO && [% of Total Workorders] >= .710,"#C6EFCE",
_30DaysCO && [% of Total Workorders] <=.700, "#FFC7CE",
"#FFF000")--Yellow

As the red part, all the values [% of Total Workorders] are greater 0.10 and less than 0.99 will all show as red("#FFC7CE"). please adjust it.

For example:

If less than 0.4 is green or greater than 0.5 is red

% of Total Workorder Color = 
VAR _30DaysBL = IF(AND(SELECTEDVALUE('Backlog Trend Data'[Backlog Timeframe - All Time]) = "Within 30 Days",SELECTEDVALUE('Backlog Trend Data'[Workorder Category])="Backlog"),True,False)
VAR _30DaysCO = IF(AND(SELECTEDVALUE('Backlog Trend Data'[Backlog Timeframe - All Time]) = "Within 30 Days",SELECTEDVALUE('Backlog Trend Data'[Workorder Category])="Closeout"),True,False)
VAR _31DaysBL = IF(AND(SELECTEDVALUE('Backlog Trend Data'[Backlog Timeframe - All Time]) ="31 - 60 Days",SELECTEDVALUE('Backlog Trend Data'[Workorder Category])="Backlog"),True,False)
VAR _31DaysCO = IF(AND(SELECTEDVALUE('Backlog Trend Data'[Backlog Timeframe - All Time]) ="31 - 60 Days",SELECTEDVALUE('Backlog Trend Data'[Workorder Category])="Closeout"),True,False)
VAR _61DaysBL = IF(AND(SELECTEDVALUE('Backlog Trend Data'[Backlog Timeframe - All Time])="61+ Days",SELECTEDVALUE('Backlog Trend Data'[Workorder Category])="Backlog"),True,False)
VAR _61DaysCO = IF(AND(SELECTEDVALUE('Backlog Trend Data'[Backlog Timeframe - All Time]) ="61+ Days",SELECTEDVALUE('Backlog Trend Data'[Workorder Category])="Closeout"),True,False)

RETURN

SWITCH(
    TRUE(),
_61DaysBL && [% of Total Workorders] <=.49, "#C6EFCE",--Green
_61DaysBL && [% of Total Workorders] >= .50,"#FFC7CE",--Red
_31DaysBL && [% of Total Workorders] <=.39, "#C6EFCE",
_31DaysBL && [% of Total Workorders] >= .40,"#FFC7CE",
_30DaysBL && [% of Total Workorders] >= .850,"#C6EFCE",
_30DaysBL && [% of Total Workorders] <=.849, "#FFC7CE",

_61DaysCO && [% of Total Workorders] <=.300, "#C6EFCE",
_61DaysCO && [% of Total Workorders] >= .319,"#FFC7CE",
_31DaysCO && [% of Total Workorders] <=.700, "#FFC7CE",
_31DaysCO && [% of Total Workorders] >= .710,"#C6EFCEE",
_30DaysCO && [% of Total Workorders] >= .710,"#C6EFCE",
_30DaysCO && [% of Total Workorders] <=.700, "#FFC7CE",
"#FFF000")--Yellow

Result:

6.JPG

 

Best Regards,

Lin

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

11 REPLIES 11
KMcCarthy9
Helper IV
Helper IV

This is the current visual, showing percent of all. 

image.png


Conditional formatting not working when choosing % of CT:
image.pngFor Within 30 Days = >85% should be green
For 31-60 Days > 10% should be red

hi, @KMcCarthy9 

You just need to adjust your formula 

% of Total Workorders = VAR _FilterCount = COUNTROWS('workorder')
VAR _AllCount = CALCULATE(COUNTROWS('workorder'),ALLSELECTED(workorder[Backlog Timeframe]))

RETURN

DIVIDE(_FilterCount,_AllCount)

Then don't use "select "Show as % of CT""

Result:

3.JPG

 

 

Best Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-lili6-msft ,
Using your formula gives me the result of 100% in each cell:
image.png

% of Total Workorders3 = VAR _FilterCount = COUNTROWS('workorder')
VAR _AllCount = CALCULATE(COUNTROWS('workorder'),ALLSELECTED(workorder[Backlog Timeframe]))

RETURN

DIVIDE(_FilterCount,_AllCount)

Hi again @v-lili6-msft , 

I wanted to add in that Backlog Timeframe is a conditional column. I'm not sure if that's why it's giving me trouble. 

 

Thank you! 

Hi @v-lili6-msft , I will try and supply some sample data, in the meantime I believe I just discovered more of the issue. 

Using the DAX Formula you supplied, it does give me the % of CT, until I sort the Timeframe the way I want. I need to it to go in order - Within 30 Days, 31 - 60 Days, and 61+ Days. To achieve this I made a conditonal column where 1 = Within 30 Days, and so on. I then ordered the Backlog Timeframe on that 1,2,3 column and all the percentages change to 100%. 

Any way to keep the % of CT and sort the way I need?

hi, @KMcCarthy9 

If possible, could you share your sample pbix file for us have a test?

There should be something wrong in other.

 

Best Regards,

Lin

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.


@v-lili6-msft wrote:

hi, @KMcCarthy9 

If possible, could you share your sample pbix file for us have a test?

There should be something wrong in other.

 

Best Regards,

Lin

 


Hi Lin, Beginner question here...how do I share a sample file with you? Thank you. 

hi, @KMcCarthy9 

Sample data and expected output would help tremendously.
https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

You can upload it to OneDrive and post the link here. Do mask sensitive data before uploading.

 

Best Regards,

Lin

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-lili6-msft 
Thank you so much for all the information. It is very appreciated. 

Here is my sample file. It is a very stripped down, simplistic version, but still has the same issue. 
https://1drv.ms/u/s!AhU3XQlTk1LVglGqGMmx55Qz-Y-g?e=WosJwS

NOTE: I was able to somewhat solve my problem by changing "Within 30 Days" to just "30 Days." By doing this I didn't have to manually sort and the %'s stayed the same. But I would like to know why when sorting it messed up the % of column totals. 

Thank you!!  

hi, @KMcCarthy9 

1. For your requirement, you want  "% of CT" in the matrix, you should use ALLSELECTED([Backlog Timeframe]) in formula like below:

% of Total Workorders = 
VAR _FilterCount = COUNTROWS('Backlog Trend Data')
VAR _AllCount = CALCULATE(COUNTROWS('Backlog Trend Data'),ALLSELECTED('Backlog Trend Data'[Backlog Timeframe - All Time]))

RETURN

DIVIDE(_FilterCount,_AllCount)

and you said it gives you the result of 100% in each cell.

So there should be a dim Backlog Timeframe table, please replace ALLSELECTED(workorder[Backlog Timeframe]) with it.

2. In this sample pbix, I find that there is a logic error in your formula:

% of Total Workorder Color = 
VAR _30DaysBL = IF(AND(SELECTEDVALUE('Backlog Trend Data'[Backlog Timeframe - All Time]) = "Within 30 Days",SELECTEDVALUE('Backlog Trend Data'[Workorder Category])="Backlog"),True,False)
VAR _30DaysCO = IF(AND(SELECTEDVALUE('Backlog Trend Data'[Backlog Timeframe - All Time]) = "Within 30 Days",SELECTEDVALUE('Backlog Trend Data'[Workorder Category])="Closeout"),True,False)
VAR _31DaysBL = IF(AND(SELECTEDVALUE('Backlog Trend Data'[Backlog Timeframe - All Time]) ="31 - 60 Days",SELECTEDVALUE('Backlog Trend Data'[Workorder Category])="Backlog"),True,False)
VAR _31DaysCO = IF(AND(SELECTEDVALUE('Backlog Trend Data'[Backlog Timeframe - All Time]) ="31 - 60 Days",SELECTEDVALUE('Backlog Trend Data'[Workorder Category])="Closeout"),True,False)
VAR _61DaysBL = IF(AND(SELECTEDVALUE('Backlog Trend Data'[Backlog Timeframe - All Time])="61+ Days",SELECTEDVALUE('Backlog Trend Data'[Workorder Category])="Backlog"),True,False)
VAR _61DaysCO = IF(AND(SELECTEDVALUE('Backlog Trend Data'[Backlog Timeframe - All Time]) ="61+ Days",SELECTEDVALUE('Backlog Trend Data'[Workorder Category])="Closeout"),True,False)

RETURN

SWITCH(
    TRUE(),
_61DaysBL && [% of Total Workorders] <=.049, "#C6EFCE",--Green
_61DaysBL && [% of Total Workorders] >= .050,"#FFC7CE",--Red
_31DaysBL && [% of Total Workorders] <=.099, "#C6EFCE",
_31DaysBL && [% of Total Workorders] >= .010,"#FFC7CE",
_30DaysBL && [% of Total Workorders] >= .850,"#C6EFCE",
_30DaysBL && [% of Total Workorders] <=.849, "#FFC7CE",

_61DaysCO && [% of Total Workorders] <=.300, "#C6EFCE",
_61DaysCO && [% of Total Workorders] >= .319,"#FFC7CE",
_31DaysCO && [% of Total Workorders] <=.700, "#FFC7CE",
_31DaysCO && [% of Total Workorders] >= .710,"#C6EFCEE",
_30DaysCO && [% of Total Workorders] >= .710,"#C6EFCE",
_30DaysCO && [% of Total Workorders] <=.700, "#FFC7CE",
"#FFF000")--Yellow

As the red part, all the values [% of Total Workorders] are greater 0.10 and less than 0.99 will all show as red("#FFC7CE"). please adjust it.

For example:

If less than 0.4 is green or greater than 0.5 is red

% of Total Workorder Color = 
VAR _30DaysBL = IF(AND(SELECTEDVALUE('Backlog Trend Data'[Backlog Timeframe - All Time]) = "Within 30 Days",SELECTEDVALUE('Backlog Trend Data'[Workorder Category])="Backlog"),True,False)
VAR _30DaysCO = IF(AND(SELECTEDVALUE('Backlog Trend Data'[Backlog Timeframe - All Time]) = "Within 30 Days",SELECTEDVALUE('Backlog Trend Data'[Workorder Category])="Closeout"),True,False)
VAR _31DaysBL = IF(AND(SELECTEDVALUE('Backlog Trend Data'[Backlog Timeframe - All Time]) ="31 - 60 Days",SELECTEDVALUE('Backlog Trend Data'[Workorder Category])="Backlog"),True,False)
VAR _31DaysCO = IF(AND(SELECTEDVALUE('Backlog Trend Data'[Backlog Timeframe - All Time]) ="31 - 60 Days",SELECTEDVALUE('Backlog Trend Data'[Workorder Category])="Closeout"),True,False)
VAR _61DaysBL = IF(AND(SELECTEDVALUE('Backlog Trend Data'[Backlog Timeframe - All Time])="61+ Days",SELECTEDVALUE('Backlog Trend Data'[Workorder Category])="Backlog"),True,False)
VAR _61DaysCO = IF(AND(SELECTEDVALUE('Backlog Trend Data'[Backlog Timeframe - All Time]) ="61+ Days",SELECTEDVALUE('Backlog Trend Data'[Workorder Category])="Closeout"),True,False)

RETURN

SWITCH(
    TRUE(),
_61DaysBL && [% of Total Workorders] <=.49, "#C6EFCE",--Green
_61DaysBL && [% of Total Workorders] >= .50,"#FFC7CE",--Red
_31DaysBL && [% of Total Workorders] <=.39, "#C6EFCE",
_31DaysBL && [% of Total Workorders] >= .40,"#FFC7CE",
_30DaysBL && [% of Total Workorders] >= .850,"#C6EFCE",
_30DaysBL && [% of Total Workorders] <=.849, "#FFC7CE",

_61DaysCO && [% of Total Workorders] <=.300, "#C6EFCE",
_61DaysCO && [% of Total Workorders] >= .319,"#FFC7CE",
_31DaysCO && [% of Total Workorders] <=.700, "#FFC7CE",
_31DaysCO && [% of Total Workorders] >= .710,"#C6EFCEE",
_30DaysCO && [% of Total Workorders] >= .710,"#C6EFCE",
_30DaysCO && [% of Total Workorders] <=.700, "#FFC7CE",
"#FFF000")--Yellow

Result:

6.JPG

 

Best Regards,

Lin

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-lili6-msft, this is extremely delayed and I apologize but wanted to thank you for taking the time to help me with this issue. 

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.