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

Preparing for a certification exam? Ask exam experts all your questions on May 15th. Register now.

Reply
Lumbisno
Regular Visitor

Change the color of a bar chart depending on the amout of data points used

Hello!  I have a barchart where each bar is an averaged measurement. I'm trying to make the bars appear a different colour if the amount of data points used for this average are few (< 3 for example).

This way I can visually distinguish possible low-trust measurements which are not based in a lot of data.

Is there any way to do this? Thanks in advance

7 REPLIES 7
Anonymous
Not applicable

Hi, @Lumbisno 

Have you solved your problem? If so, can you share your solution here and mark the correct answer as a standard answer to help other members find it faster? Thank you very much for your kind cooperation!

 

Best Regards

Yongkang Hua

Ritaf1983
Super User
Super User

Hi @Lumbisno 
You can use a measure like :

color =
var count_points= COUNTROWS('Table')
Return
if (count_points<3, "red","grey")
(the colos can be used as a xeca codes too)

After you have this measure you can use it as a condition for bar color formatting:
Ritaf1983_0-1740164890299.png

Result :

Ritaf1983_1-1740165076731.png

I used a subtitle for a legend.
PBIX is attached
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Hello! thank you for your reply and your help. Unfortunately I think because of how my data is formatted, this way does not work. The problem I have is detailed in my answer to Freginier. Is there any way to work around it?

Hi @Lumbisno 
Apologies, but I didn't understand how the data structure you provided differs from the one I demonstrated...
Did you download the PBIX attached?
Anyway, I replaced my data with yours, and it seems that the result is exactly what you requested..

Ritaf1983_0-1740174263625.png

The updated pbix is also attached
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

I'm sorry, I did not explain myself properly. The reason I created different measures is because there are different base colours for the bars ( see image below).

Lumbisno_0-1740487838915.png

So I would need for the bars to each keep the original colour or to change to that "low trust" colour.
Thank you very much for your help and I apologise for the confusion.

freginier
Solution Sage
Solution Sage

Hey there!

 

Power BI allows you to conditionally format bar colors using DAX and field-based conditional formatting.

First you need to create a measure that counts the number of data points used for each bar: 

DataPointCount = COUNT('Table'[Value])

 

Next you can create a measure that assigns a color code based on the number of data points:

BarColor =
VAR CountDataPoints = [DataPointCount]
RETURN
IF( CountDataPoints < 3, "Red", "Blue" )

 

Finally, apply Conditional Formatting in the Bar Chart: 

1. Select your bar chart in Power BI.
2. Click on Format (Paint Roller) → Columns.
3. Find the "Color" option and click the fx (conditional formatting) button.
4. In the "Based on field" dropdown, select the "BarColor" measure.
5. Set the formatting to match Red & Blue accordingly.

 

Hope this helps!

😁😁

Hi! thanks you very much for the help! I got it started but I ran into the following problem:
My data set looks like this:

A1
A5
B2
C4
B7
D1
A3
B5

Each bar in my chart is an average of the second column grouped by the first column, which we could call the "vendors" (A,B,C or D). For example ,in this data set the bar for the averaged values corresponding to the vendors "C" and "D" should appear a different colour because they have very few data points.
With your solution as i understood it I made 4 separate count measures and for each one a bar color measure.
Unfortunately it appears that the conditional formatting for the bars applies a single rule to all bars, while in my case each bar has to look to it's own rule. Do you know any way to work around this? thank you again!

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

Check out the April 2025 Power BI update to learn about new features.

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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