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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
DataNinja777
Super User
Super User

How to color negative number in red in stacked bar chart

Hi Power BI Community,

 

I am trying to conditionally format the color of the stacked bar chart by coloring negative numbers in red and postive numbers in green.  I am trying to change the blue circled fields to Min and Number, but when I save them they get changed to the default value.  I'd greatly appreciate it if anyone could let me know how to apply conditional formatting.  

DataNinja777_0-1709392645144.png

Thank you for your help.  

 

1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @DataNinja777 ,

You can use a measure that checks whether another measure's value is positive or negative and returns a color based on a condition. This is a sample:

Text Color = 
IF ( [Sum of Numbers] < 0, "Red", "Green" )
//the color can be replaced with hexadecimal codes like #6B2328

danextian_0-1709394280691.png

 

Please see attached sample pbix

 





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.

View solution in original post

17 REPLIES 17
Anonymous
Not applicable

Hi @DataNinja777 ,

 

I tested the solution provided by @danextian  and it outputs the results correctly. You mentioned that an error occurs when you modify the measure, can you provide details of the error message and the expected result?

 

vtangjiemsft_0-1709618273477.png

vtangjiemsft_3-1709618582221.png

vtangjiemsft_4-1709618624696.pngvtangjiemsft_5-1709618644772.png

Best Regards,

Neeko Tang

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

Hi @Anonymous 

 

Thank you for your sample file, too.  Your solution is exactly what I am after, however, when I tried to do the same in my data model, using exactly the same visual, same color measure and the same conditional formatting configuration, I get the visual like below, which is not respecting the color conditional formatting.  

DataNinja777_1-1710125387732.png

I'd greatly appreciate it if you could shed some light as to why this is happening in my pbix visualization.  

Thank you for your help!

 

Anonymous
Not applicable

Hi @DataNinja777 ,

 

Can you please share more details to help us clarify your scenario?
Please share me with your pbix file after removing sensitive data.

Refer to:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

 

Best Regards,

Neeko Tang

Hi @Anonymous 

Thanks for your help.  When I created a simple sum measure, it worked in other visual within the same pbix file but in this particular measure visualization, it is not working.  The measure I am trying to using this conditional formatting is as follows:

DataNinja777_1-1710127906953.png

 

DataNinja777_2-1710127958908.png

DataNinja777_3-1710128075012.png

Unfortunately, I cannot share the pbix file, and it takes time to annonimize the data, so I am trying to find a solution by investigating the measure which may be causing this issue.  

Thank you for your help!

Anonymous
Not applicable

Hi @DataNinja777 ,

 

I tested your measure and the conditional format still displays correctly.
You can convert the bar chart to a table visual to see if the measure outputs correctly.

vtangjiemsft_0-1710146005000.pngvtangjiemsft_1-1710146015550.pngvtangjiemsft_2-1710146023448.pngvtangjiemsft_3-1710146033426.png

Then the result is as follows.

 

vtangjiemsft_4-1710146073631.png

 

 

Best Regards,

Neeko Tang

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

Thank you @Anonymous for your help.  

In fact, when I changed the y-axis dimension to GL account, the color was as designed and intended.  However, the issue still remains if I use mmm-yyyy as the dimension.  I am not sure why when time dimension is used the coloring doesn't behave in the way intended.  I guess there is some difficult dax filter condition or something like that is involved, but I am not sure how to address this issue.  Do you think if I change measures to respect the filtering of mmm-yyyy, the coloring will behave in the intended way?  Thanks a lot for your help.

Anonymous
Not applicable

Hi @DataNinja777 ,

 

Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or if you are still confused about it, please feel free to let me know.

 

Best Regards,

Neeko Tang

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

Hi @Anonymous 

Thanks for your continued follow up on this issue.  I've created a dummy data and tested the simplified version of my issue I am facing.  Doing this clarified my issue further, and I noticed that when I use the numerical field in the 2nd table and try to use that as the filter in the 1st visual which I want to color the negative value as red, it doesn't behave in the intended way.  If I don't use the 2nd chart to filter the 1st chart, the solution which @danextian and @Anonymous provided works in the way intended.  

DataNinja777_0-1712372022858.png

The issue with this chart is, 

- The trial balance adds up to zero at every time dimension field

- The trial balance should not be added across time dimension and only added within a particular time point (therefore, max of the calendar table date was used)

- When I put the trial balance measure in a visual without specifying time field, it shows blank value due to it always adding up to zero.

- When I put the visual without GL account category, it also shows zero due to it adding up to zero all the time

Because of this, I've created a 2nd chart which specifies the category and the amount at the max date, but with the combination of these two charts, the 1st chart no longer respects the coloring formula in the Bars section.  

 

DataNinja777_1-1712373862436.png

DataNinja777_2-1712373908053.png

 

Thanks for your help.  

Hi @Anonymous ,

 

Thanks for your message.  The issue hasn't been resolved.  While the visual behaves in the expected way when I use the GL account as the Y-axis, when I use yyyy-mm as the Y-axis dimension, it doesn't behave in the expected manner.  I will investigate the reason for this.  I think it could be due to the filtering of yyyy-mm.

Anonymous
Not applicable

Hi @DataNinja777 ,

 

I'm not quite sure what you mean. In my output, the y-axis is using a date field and he is coloring normally.

You can convert the bar chart to a table visual to see if the measure outputs correctly. Or provide a sample pbix.(Careful protection of data privacy)

vtangjiemsft_0-1710207682616.pngvtangjiemsft_1-1710207784469.pngvtangjiemsft_2-1710207818349.png

 

Best Regards,

Neeko Tang

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

 

 

Musadev
Resolver III
Resolver III

Hi @DataNinja777 
Check the screenshot and the defined rules.

Musadev_0-1709395907797.png

 

Hi @Musadev 

 

Thanks, I did the same as your screenshot, but that didn't produce the color I am trying to show.  

DataNinja777_0-1709438382625.png

 

Rahul_2645
Regular Visitor

Rahul_2645_0-1709394766143.png

Hi,
You can try this approach.

Hi @Rahul_2645 

Thanks, and I have been trying to do the same as your configuration for a while, but when I save it, like below, 

DataNinja777_2-1709438631269.png

The next time, when I open the configuration screen comes up like below:

DataNinja777_3-1709438684244.png

 

and the color is not changed to the required coloring.  

 

danextian
Super User
Super User

Hi @DataNinja777 ,

You can use a measure that checks whether another measure's value is positive or negative and returns a color based on a condition. This is a sample:

Text Color = 
IF ( [Sum of Numbers] < 0, "Red", "Green" )
//the color can be replaced with hexadecimal codes like #6B2328

danextian_0-1709394280691.png

 

Please see attached sample pbix

 





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.

Hi @danextian 

It appears that the Text Color measure is disregarding the filter applied to the stacked bar chart visualization, i.e., it is coloring based on the the total of the measure without taking into account of the filters applied such as yyyy-mm used in the Y-axis.  How can I change the text color measure or the bar color conditional formatting so that the colors respect the filters being applied to the visualization, such as yyy-mm in Y-axis?  

Hi @danextian 

Thanks for your input.  I tried to do like below, but and I am trying to change the color of the bar chart depending on the sign of the value, but it is not having the impact.  When I remove the "" from the color code, the formula shows error.  How can I use the color code in this formula?  

DataNinja777_4-1709439180588.png

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

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.

June 2025 community update carousel

Fabric Community Update - June 2025

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