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

Conditional Formatting not working

I'm trying to set conditional formatting in a table. Because of the different data types, two fields (Tar Diff and Int Tar Diff) have been combined in a measure with the correct formatting so that they can go in one graph.

I am then applying an if statement to give me background colors based on if they are above zero or not. Because of management suggestions, its actually closer whether it is below 0.5 or not.

 

You can see in the picture below the table in question and the offending code.

Capture.PNG

Tar Diff is a %, hence the extra decimals, and Int Tar Diff is a whole number. 

 

No matter how I change the formula, that -1 still stays green! Completely baffled!

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Hi @v-lid-msft,

 

Unfortunately that just made everything blank in terms of colour!

 

I did, however, find a solution:

 

TarKPIColour = 
IF ([Int Tar Diff] <> "" || [Tar Diff] <> "",
IF ([Tar Diff] >= -0.005 && [Int Tar Diff] >= 0.5, "#30a316", "#d10a14"))

Not entirely sure why, but it works!

View solution in original post

7 REPLIES 7
v-lid-msft
Community Support
Community Support

Hi @EpicTriffid ,

 

How do you combine two fields into a measure? Maybe in this context, you show [Int Tar Diff] as -1, but it calculate [Tar Diff] first in color measure and get the green color.

 

Could you please describle the formula about combing [Int Tar Diff] and [Int Tar Diff]? Please don't have any Confidential Information or Real data in your reply.

 

Best regards,

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

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

Hi @v-lid-msft 

 

So, it my data I have values either in percentages, or in whole numbers. Some of these are actuals, and some targets. We show the actuals as they are, but we use targets in a Difference from Target measure, which just subtracts Actuals from Targets. We have to do this in one measure for the whole numbers (Int Tar Diff), and in another measure for percentages (Tar Diff). An example of this code is below:

Tar Diff = 
IF(SUM(KPIs_COMBINED_RESHAPED[KPI Targets]) <> 0 && (SUM(KPIs_COMBINED_RESHAPED[KPI Actuals])) <> 0,
SUM(KPIs_COMBINED_RESHAPED[KPI Actuals]) - SUM(KPIs_COMBINED_RESHAPED[KPI Targets]),"")

We then need to combine both of these measures into one table, but so we can whole numbers and percetnages side by side. So to format that I use:

Tar Diff Table = SWITCH(VALUES(KPIs_COMBINED_RESHAPED[KPI]), "INT_ENR", FORMAT([Int Tar Diff], "0"), FORMAT([Tar Diff],"0%"))

This then allows the data to show up as it does above. 

Hi @EpicTriffid ,

 

We can try to use the following measure as the new field value to meet your requirement:

 

ColorMeasure =
IF (
    [Int Tar Diff] <> ""
        || [Tar Diff] <> "",
    SWITCH (
        VALUES ( KPIs_COMBINED_RESHAPED[KPI] ),
        IF ( [Int Tar Diff] >= 0.5, "#30a316", "d10a14" ), IF ( [Tar Diff] >= -0.005, "#30a316", "d10a14" )
    ),
    ""
)

Best regards,

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

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

Hi @v-lid-msft,

 

Unfortunately that just made everything blank in terms of colour!

 

I did, however, find a solution:

 

TarKPIColour = 
IF ([Int Tar Diff] <> "" || [Tar Diff] <> "",
IF ([Tar Diff] >= -0.005 && [Int Tar Diff] >= 0.5, "#30a316", "#d10a14"))

Not entirely sure why, but it works!

Hi @EpicTriffid ,


Glad to hear that you have resolved your problem. Would you please kindly mark your sharing solution as an answer so that it can benefit more users?

 

Best regards,

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

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

Hi @EpicTriffid 

 

The only way I could make it works was doing the following metric:

TarKPIColour = SWITCH (

   SUM([Tar Diff]) >= -0.005, "#30a316",

   SUM([Tar Diff])  <-0.005, "#d10a14",

...)

 

 

hi @Anonymous 

 

Thanks for that. I had to use SUMX in order to get the measure, but the visualisation failed saying it can compare boolean values with text values. Not sure where it's getting hung up...

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.