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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
ls784
Frequent Visitor

Conditional formatting based on multiple other values

Hello

I'm wondering if it's possible to conditionally format cells based on more than one other value.

ls784_0-1733748051873.png

Ideally I'd like to conditionally format a cell to show counts of each of the different response rates. I've got a lot of rows in this data so I dont want to have to create a separate bar visual for each line.

 

Any advice would be appreciated!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @ls784 , hello danextian and divyed, thank you for your prompt reply!

Create a calcualted column as shown as shown below:

Column = VAR __Total = ('Table'[Strongly Disagree]) + ('Table'[Disagree]) +('Table'[Neither Agree nor Disagree]) + ('Table'[Agree]) + ('Table'[Strongly Agree])

VAR __Width1 = DIVIDE(('Table'[Strongly Disagree]), __Total, 0) * 1000
VAR __Width2 = DIVIDE(('Table'[Disagree]), __Total, 0) * 1000
VAR __Width3 = DIVIDE(('Table'[Neither Agree nor Disagree]), __Total, 0) * 1000
VAR __Width4 = DIVIDE(('Table'[Agree]), __Total, 0) * 1000
VAR __Width5 = DIVIDE(('Table'[Strongly Agree]), __Total, 0) * 1000

VAR __Start2 = __Width1
VAR __Start3 = __Width1 + __Width2
VAR __Start4 = __Width1 + __Width2 + __Width3
VAR __Start5 = __Width1 + __Width2 + __Width3 + __Width4

VAR __Color1 = "Red"
VAR __Color2 = "Orange"
VAR __Color3 = "Gray"
VAR __Color4 = "LightGreen"
VAR __Color5 = "Green"

VAR __header = "data:image/svg+xml;utf8," &
               "<svg xmlns='http://www.w3.org/2000/svg' x='0px' y='0px' width='1000' height='200'>"
VAR __footer = "</svg>"

VAR __Rect1 = "<rect x='0' y='0' width='" & __Width1 & "' height='200' style='fill:" & __Color1 & ";stroke-width:0;' />"
VAR __Rect2 = "<rect x='" & __Start2 & "' y='0' width='" & __Width2 & "' height='200' style='fill:" & __Color2 & ";stroke-width:0;' />"
VAR __Rect3 = "<rect x='" & __Start3 & "' y='0' width='" & __Width3 & "' height='200' style='fill:" & __Color3 & ";stroke-width:0;' />"
VAR __Rect4 = "<rect x='" & __Start4 & "' y='0' width='" & __Width4 & "' height='200' style='fill:" & __Color4 & ";stroke-width:0;' />"
VAR __Rect5 = "<rect x='" & __Start5 & "' y='0' width='" & __Width5 & "' height='200' style='fill:" & __Color5 & ";stroke-width:0;' />"

VAR __SVG = __header & __Rect1 & __Rect2 & __Rect3 & __Rect4 & __Rect5 & __footer
RETURN
    __SVG

Result for your reference:

vyajiewanmsft_0-1733813268769.png

Best regards,

Joyce

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi @ls784 , hello danextian and divyed, thank you for your prompt reply!

Create a calcualted column as shown as shown below:

Column = VAR __Total = ('Table'[Strongly Disagree]) + ('Table'[Disagree]) +('Table'[Neither Agree nor Disagree]) + ('Table'[Agree]) + ('Table'[Strongly Agree])

VAR __Width1 = DIVIDE(('Table'[Strongly Disagree]), __Total, 0) * 1000
VAR __Width2 = DIVIDE(('Table'[Disagree]), __Total, 0) * 1000
VAR __Width3 = DIVIDE(('Table'[Neither Agree nor Disagree]), __Total, 0) * 1000
VAR __Width4 = DIVIDE(('Table'[Agree]), __Total, 0) * 1000
VAR __Width5 = DIVIDE(('Table'[Strongly Agree]), __Total, 0) * 1000

VAR __Start2 = __Width1
VAR __Start3 = __Width1 + __Width2
VAR __Start4 = __Width1 + __Width2 + __Width3
VAR __Start5 = __Width1 + __Width2 + __Width3 + __Width4

VAR __Color1 = "Red"
VAR __Color2 = "Orange"
VAR __Color3 = "Gray"
VAR __Color4 = "LightGreen"
VAR __Color5 = "Green"

VAR __header = "data&colon;image/svg+xml;utf8," &
               "<svg xmlns='http://www.w3.org/2000/svg' x='0px' y='0px' width='1000' height='200'>"
VAR __footer = "</svg>"

VAR __Rect1 = "<rect x='0' y='0' width='" & __Width1 & "' height='200' style='fill:" & __Color1 & ";stroke-width:0;' />"
VAR __Rect2 = "<rect x='" & __Start2 & "' y='0' width='" & __Width2 & "' height='200' style='fill:" & __Color2 & ";stroke-width:0;' />"
VAR __Rect3 = "<rect x='" & __Start3 & "' y='0' width='" & __Width3 & "' height='200' style='fill:" & __Color3 & ";stroke-width:0;' />"
VAR __Rect4 = "<rect x='" & __Start4 & "' y='0' width='" & __Width4 & "' height='200' style='fill:" & __Color4 & ";stroke-width:0;' />"
VAR __Rect5 = "<rect x='" & __Start5 & "' y='0' width='" & __Width5 & "' height='200' style='fill:" & __Color5 & ";stroke-width:0;' />"

VAR __SVG = __header & __Rect1 & __Rect2 & __Rect3 & __Rect4 & __Rect5 & __footer
RETURN
    __SVG

Result for your reference:

vyajiewanmsft_0-1733813268769.png

Best regards,

Joyce

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Ah this perfect thank you, I never would have got there by myself

danextian
Super User
Super User

You mean you want to have this multi-colored databar for each row?

danextian_0-1733752429999.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Yep! Do you think this is possible?

divyed
Super User
Super User

Hello @ls784 ,

 

You can create a dax measure and use it for conditional formatting. Dax measure can use multiple fileds and values to give you desired outcome.

Step 1 : Create a dax measure as per need

Step 2 : Use this dax measure for conditionally format your values

 

I hope this helps.

 

Did I answer your query ? Mark this as solution if this helps, Kudos are appreciated.

Cheers

LinkedIn : https://www.linkedin.com/in/neeraj-kumar-62246b26/
ls784
Frequent Visitor

Hello

The problem is I don't know the DAX measure that will give me the result I need? Can't figure out how to get a measure to bring back the length of bars and the colours for each line.

Thanks

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.