Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! 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.
@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.
Proud to be a Super User! |
|
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
@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.
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
@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.
Proud to be a Super User! |
|
Check out the April 2025 Power BI update to learn about new features.
Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.
User | Count |
---|---|
106 | |
68 | |
48 | |
44 | |
42 |