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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
babyjb1979
Helper I
Helper I

How to create a colored block

Hi all,

 

I am requested to create a colored block by our client like following: the condition is if number of column a = number of column b,then green , otherwaise red.

babyjb1979_0-1687297969751.png

How can I do that? Really need help.

 

Thank you in advance!

Branko

2 REPLIES 2
PhilipTreacy
Super User
Super User

Hi @babyjb1979 

 

Download example PBIX file

 

You haven't provided a lot of detail so I don't know exactly how you want this implemented.  

 

But if you take this sample data (see file above)

 

nofil.png

 

and create a measure using this DAX.  It checks whether the slicer has anything selected, then sets a color accordingly

 

 

 

Block Color = IF(ISFILTERED('DataTable'[Thing]), IF(SELECTEDVALUE('DataTable'[a]) = SELECTEDVALUE('DataTable'[b]), "#0F0", "#F00"), "#FFF")

 

 

 

I'm using a card visual to act as the box with the color.  You could other things like a shape, or you could use a cell in a table.

 

Create a conditional formatting rule for the box that sets the color for the background and the text in the box.  If both are the same it looks like there's no text, just a colored box.

 

Select the card visual then in Visualizations -> Format -> Visual -> Callout value click the fx button to create the conditional formatting rule

 

boxcf.png

 

 

Repeat those steps for the background of the card visual.  You'll find this in General -> Effects -> Background -> fx button

 

Heres' the conditional formatting rule.  It's the same for the background and the text in the card

 

boxcfr.png

 

 

Use the slicer to select diffwerent 'Things', so for values that are the same

eq.png

 

 

and not the same

noteq.png

 

 

If you need it implemented differently, please post sample data and a clear, detailed explanation of what it is you need.

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


danextian
Super User
Super User

Hi @babyjb1979 ,

 

That calls for conditional formatting on a shape. Here's a video tutorial

https://powerplatformtrainings.com/2021/08/24/introducing-new-shapes-with-customize-shape-formatting... 










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


Proud to be a Super User!









"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.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

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