The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hi everyone,
I’m working on a Power BI report that includes a pie chart and a table. I’d like to add a column in the table that contains icons, and I want the color of these icons to match the corresponding slice colors in the pie chart.
Does anyone know how I can achieve this? Are there specific DAX expressions or formatting settings that I should use?
Solved! Go to Solution.
@Lolo_2023
Workaround 1: Yes you can format the color of these icons with the help of condition formatting option. First click on the column name on which those icons are displaying then "Condition FOrmatting" option and then "Icons" and then select them as per your wish.
Workaround 2: With the help of DAX Measure you can manage the color.
Color Measure = SWITCH( TRUE(),
Table[Column] = "your condition", "Paste HexColor code here",
Table[Column] = "your condition", "Paste HexColor code here",
so on ......
)
Then use this measure to on condition formatting as Font Color.
Not with the default icons. Use a measure that returns SVG images and use that in conditional formatting still as icons. The colors and shapes depend on certain conditions.
Conditional Icon =
VAR ShapeType =
SWITCH (
TRUE (),
[% to Subtotal] > 0.3, "Square",
[% to Subtotal] > 0.1, "Diamond",
"Circle"
)
VAR FilColor =
SELECTEDVALUE ( 'Table'[Color] ) -- Dynamic color from the table
VAR StrokeWidth = 2 -- Set to 0 to remove the borders
RETURN
SWITCH (
ShapeType,
"Circle",
"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100'>
<circle cx='50' cy='50' r='40' style='fill:" & FilColor & ";stroke-width:" & StrokeWidth & ";stroke:rgb(0,0,0)' />
</svg>",
"Square",
"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100'>
<rect x='10' y='10' width='80' height='80' style='fill:" & FilColor & ";stroke-width:" & StrokeWidth & ";stroke:rgb(0,0,0)' />
</svg>",
"Diamond",
"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100'>
<polygon points='50,10 90,50 50,90 10,50' style='fill:" & FilColor & ";stroke-width:" & StrokeWidth & ";stroke:rgb(0,0,0)' />
</svg>",
-- Default case: SVG with zero dimensions
"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='0' height='0'></svg>"
)
Note: the code gets messed up after hitting reply. Working code is in the attached pbix. SVG generated with the help of ChatGPT.
Hi @Lolo_2023
Thanks for reaching out to the Microsoft Fabric Community Forum.
To add a column with icons in a table and match their colors to the corresponding slice colors in a pie chart, follow these steps:
1.Define Colors with DAX: Create a DAX column or measure (e.g., Category Color) that assigns specific hex color codes to each category.
DAX
Category Color =
SWITCH(
TRUE(),
'Table'[Category] = "Category A", (Sample hexcode”FF5733"),
'Table'[Category] = "Category B", "#33FF57",
'Table'[Category] = "Category C", "#3357FF",
"#000000" ---Hex code for default color.
)
2. Under Conditional Formatting, select Icons. In the dialog box, Set rules or measures to display icons based on your logic (e.g., "Positive → Green Arrow," "Negative → Red Arrow").
3. Apply Background Color or Font Color conditional formatting to match the color defined in the Category Color .
If you have any further questions or need additional help with this, feel free to reach out to us for further assistance!
If you find this post helpful, please mark it as an "Accept as Solution" and give a KUDOS.
But OP was asking for conditionally formatting the icon color and not that of the font or the background.
Hi @Lolo_2023
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank you.
Hi @Lolo_2023
As we haven’t heard back from you, we wanted to kindly follow up to check if the solution we provided for your issue worked for you or let us know if you need any further assistance?
Your feedback is important to us, Looking forward to your response.
Hi @Lolo_2023
I hope this information is helpful. Please let me know if you have any further questions or if you'd like to discuss this further. If this answers your question, please Accept it as a solution and give it a 'Kudos' so others can find it easily.
Thank you.
Not with the default icons. Use a measure that returns SVG images and use that in conditional formatting still as icons. The colors and shapes depend on certain conditions.
Conditional Icon =
VAR ShapeType =
SWITCH (
TRUE (),
[% to Subtotal] > 0.3, "Square",
[% to Subtotal] > 0.1, "Diamond",
"Circle"
)
VAR FilColor =
SELECTEDVALUE ( 'Table'[Color] ) -- Dynamic color from the table
VAR StrokeWidth = 2 -- Set to 0 to remove the borders
RETURN
SWITCH (
ShapeType,
"Circle",
"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100'>
<circle cx='50' cy='50' r='40' style='fill:" & FilColor & ";stroke-width:" & StrokeWidth & ";stroke:rgb(0,0,0)' />
</svg>",
"Square",
"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100'>
<rect x='10' y='10' width='80' height='80' style='fill:" & FilColor & ";stroke-width:" & StrokeWidth & ";stroke:rgb(0,0,0)' />
</svg>",
"Diamond",
"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100'>
<polygon points='50,10 90,50 50,90 10,50' style='fill:" & FilColor & ";stroke-width:" & StrokeWidth & ";stroke:rgb(0,0,0)' />
</svg>",
-- Default case: SVG with zero dimensions
"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='0' height='0'></svg>"
)
Note: the code gets messed up after hitting reply. Working code is in the attached pbix. SVG generated with the help of ChatGPT.
@Lolo_2023
Workaround 1: Yes you can format the color of these icons with the help of condition formatting option. First click on the column name on which those icons are displaying then "Condition FOrmatting" option and then "Icons" and then select them as per your wish.
Workaround 2: With the help of DAX Measure you can manage the color.
Color Measure = SWITCH( TRUE(),
Table[Column] = "your condition", "Paste HexColor code here",
Table[Column] = "your condition", "Paste HexColor code here",
so on ......
)
Then use this measure to on condition formatting as Font Color.
Add a column to your dataset with hex codes or color names that correspond to the pie chart slice colors.
Under Conditional Formatting, apply Font Color or Background Color and base it on the custom color field.
💌 If this helped, a Kudos 👍 or Solution mark ✅ would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn