Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
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.
Solved! Go to Solution.
@Anonymous 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.
Proud to be a Super User! |
|
Hi @Anonymous ,
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
@Anonymous Hey,
I would suggest you to create a measure. Copy paste same measure but change the column reference as per your table data.
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
@Anonymous 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.
Proud to be a Super User! |
|
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 40 | |
| 37 | |
| 33 | |
| 29 | |
| 26 |
| User | Count |
|---|---|
| 134 | |
| 104 | |
| 63 | |
| 60 | |
| 55 |