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
Claudioffj
Regular Visitor

Conditional formatting for 0 values

I have a conditional formatting based on a measure that basically indicates the variartion respect last month value.
It works perfectly well except when this measure is exaclty 0 (no variation respect last month), then instead of showing yellow it shows black. Is this a bug?

The measure is basically a switch

SWITCH (
TRUE,
measure > 0, "green",
measure < 0, "red",
measure = 0, "yellow",
BLANK ()
)

 

Thanks

3 REPLIES 3
v-yohua-msft
Community Support
Community Support

Hi, @Claudioffj 

 

It might have something to do with the way Power BI interprets measures or formatting rules. Here are a few steps to troubleshoot and resolve the issue:

 

 Ensure that the measure calculations with a value of 0 are accurate. Sometimes, even subtle differences in calculations can cause conditional formatting to behave unexpectedly. Double-check that the measure actually returns 0 and not a very small number close to 0 or .

 

Although your utterances look correct, it's worth reviewing the conditional formatting rules in the Power BI interface to make sure they're logically consistent with the utterance. For a detailed guide to setting up conditional formatting, see the official documentation here:

 

Apply conditional table formatting in Power BI - Power BI | Microsoft Learn

 

Make sure that the data type of the measure and its aggregation status, if any, are compatible with the conditional formatting rules. The incompatibilities here can sometimes lead to unexpected formatting results.

 

If the problem persists after following these steps, it may be helpful to explore alternatives to the implementation logic, such as using calculated columns or different DAX functions that may handle 0 values more explicitly in the context of conditional formatting.

 

How to Get Your Question Answered Quickly 

Best Regards

Yongkang Hua

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

Hi @v-yohua-msft 

 

Yes, the result is indeed 0. If the value for the current month and the previous month is 0, the conditional formatting does not work.

My variation measure is a simple calculation of current month - previous month.

The results are as follows: 

Current Month = 10 - Previous Month = 5 = 5 => formatting OK
Current Month = 0 - Previous Month = 5 = -5 => formatting OK
Current Month = 0 - Previous Month = 0 = 0 => formatting does not work

RossEdwards
Solution Specialist
Solution Specialist

I've just created a simple 'Enter Data' model with 3 rows: -1, 0, 1.  I've placed them in a table and used a measure:

Measure Colour = var measureVal = SUM(Example[Measure])
var output = SWITCH (
TRUE,
measureVal > 0, "green",
measureVal < 0, "red",
measureVal = 0, "yellow",
BLANK ()
)
RETURN
output

I've then put those values in a table and got this result:

Screenshot.PNG

 

I can only summize there is some other element at play here that is not found in your description.

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.