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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
Tatiana-Weiss
Frequent Visitor

Dynamic Color Definition

Hello Community,

I have a question you might be able to assist with. 

I want to be able to define color of bars in a bar chart dynamically. My product id is composed of a sequence defining color, product type, etc, so I'm able to parse that. However, I want to be able to write a formula that would always define a specific hex color by a combination of color, product type, vendor and so on, so that they correspond with the product color and so that I don't need to change the color of the bars everytime I create a new viz. Is it possible to do that?

Any advice would be highly appreciated.

1 ACCEPTED SOLUTION
bhanu_gautam
Super User
Super User

@Tatiana-Weiss In Power BI Desktop, go to the Data view.
Select the table where your product data is stored.
Create a new calculated column that determines the hex color code based on your criteria. For example:

DAX
ProductColorHex =
SWITCH(
TRUE(),
'Table'[ProductType] = "Type1" && 'Table'[Vendor] = "VendorA", "#FF5733",
'Table'[ProductType] = "Type2" && 'Table'[Vendor] = "VendorB", "#33FF57",
'Table'[ProductType] = "Type3" && 'Table'[Vendor] = "VendorC", "#3357FF",
"#000000" // Default color
)

Go to the Report view.
Add a bar chart visual to your report.
Add the necessary fields to the Axis and Values sections of the bar chart.
Click on the bar chart to select it, then go to the Format pane.
Expand the Data colors section.
Click on the fx button next to Default color to open the Conditional formatting window.
In the Conditional formatting window, set the Based on field to the calculated column you created (e.g., ProductColorHex).
Choose the Summarization method (e.g., First, Last, etc.) and click OK.

 




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

4 REPLIES 4
Tatiana-Weiss
Frequent Visitor

Briliant @bhanu_gautam @HarishKM !

Thank you both so much!

v-sdhruv
Community Support
Community Support

Hi @Tatiana-Weiss ,
Just wanted to check if you had the opportunity to review the suggestions provided?
If the response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank You

HarishKM
Solution Sage
Solution Sage

@Tatiana-Weiss Hey,
I would suggest you to create a measure. Copy paste same measure but change the column reference as per your table data.

 

Dynamic CF =
SWITCH(TRUE(),
SELECTEDVALUE(financials[Product])="Amarilla" && SELECTEDVALUE(financials[Segment])= "Channel Partners","Green",
SELECTEDVALUE(financials[Product])="Amarilla" && SELECTEDVALUE(financials[Segment])= "Small Business","Olive",
SELECTEDVALUE(financials[Product])="Amarilla" && SELECTEDVALUE(financials[Segment])= "Goverment","Red",
SELECTEDVALUE(financials[Product])="Amarilla" && SELECTEDVALUE(financials[Segment])= "Midmarket","Blue","Grey")
 
once you have created dynamic CF measure then click on your visual and go to format pane on right side.

scroll down to Value section at the bottom then click conditional formatting and then below option will apear as per image.
HarishKM_0-1744804032642.png

 

update your conditional formating as above and this will fulfill your requirement.

 

 

Thanks
Harish M
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly and give Kudos if helped you resolve your query

bhanu_gautam
Super User
Super User

@Tatiana-Weiss In Power BI Desktop, go to the Data view.
Select the table where your product data is stored.
Create a new calculated column that determines the hex color code based on your criteria. For example:

DAX
ProductColorHex =
SWITCH(
TRUE(),
'Table'[ProductType] = "Type1" && 'Table'[Vendor] = "VendorA", "#FF5733",
'Table'[ProductType] = "Type2" && 'Table'[Vendor] = "VendorB", "#33FF57",
'Table'[ProductType] = "Type3" && 'Table'[Vendor] = "VendorC", "#3357FF",
"#000000" // Default color
)

Go to the Report view.
Add a bar chart visual to your report.
Add the necessary fields to the Axis and Values sections of the bar chart.
Click on the bar chart to select it, then go to the Format pane.
Expand the Data colors section.
Click on the fx button next to Default color to open the Conditional formatting window.
In the Conditional formatting window, set the Based on field to the calculated column you created (e.g., ProductColorHex).
Choose the Summarization method (e.g., First, Last, etc.) and click OK.

 




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






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.

Top Solution Authors