Forum Discussion
Help with conditional formatting in power bi
- 11 months ago
Hi Poornima2023 ,
Finally I achieved this using SVG:
This svg feature helps to give conditional formatting based on the data we have.
Here is the mcode that i used:let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wck0sLlHSUXLKKM0rS8xLLc4oTyxSitWJVvLLLyrJAMo4ZyTmpWSmJxZlgIWD80uhwql5eYmZSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Region = _t, #"Branch " = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Region", type text}, {"Branch ", type text}}), #"Added Conditional Column" = Table.AddColumn(#"Changed Type", "svg", each if [Region] = "East" then "data:image/svg+xml;utf8," & "<svg width='200' height='100' xmlns='http://www.w3.org/2000/svg'>" & "<rect x='10' y='10' width='180' height='80' fill='#2196F3' stroke='#333' stroke-width='2' rx='10' ry='10'/>" & "<text x='100' y='55' font-size='20' font-family='Arial' fill='white' text-anchor='middle' dominant-baseline='middle'>East</text>" & "</svg>" else if [Region] = "North" then "data:image/svg+xml;utf8," & "<svg width='200' height='100' xmlns='http://www.w3.org/2000/svg'>" & "<rect x='10' y='10' width='180' height='80' fill='#4CAF50' stroke='#333' stroke-width='2' rx='10' ry='10'/>" & "<text x='100' y='55' font-size='20' font-family='Arial' fill='white' text-anchor='middle' dominant-baseline='middle'>North</text>" & "</svg>" else if [Region] = "South" then "data:image/svg+xml;utf8," & "<svg width='200' height='100' xmlns='http://www.w3.org/2000/svg'>" & "<rect x='10' y='10' width='180' height='80' fill='#FF9800' stroke='#333' stroke-width='2' rx='10' ry='10'/>" & "<text x='100' y='55' font-size='20' font-family='Arial' fill='white' text-anchor='middle' dominant-baseline='middle'>South</text>" & "</svg>" else null) in #"Added Conditional Column"Does this resolve your issue? let me know
Best regards,
Region and Branch cannot be formatted, unfortunately. Matrix visuals don't allow it.
A-E and Total can be.
See example screenshot, using a measure to define the rules and then applying to the matrix on EACH of your columns (individually).
Its coming like below
- V-yubandi-msft11 months agoCommunity Support
Hi Poornima2023 ,
As KNP mentioned earlier, conditional formatting cannot be applied to row headers such as Region and Branch in the matrix visual, so those fields cannot be colored. For any blanks that appear, you can adjust your measure logic to replace them with 0 or another value, which will help ensure conditional formatting is applied consistently.
Hope this helps, and thank you for your response, KNP .