Forum Discussion

babyjb1979's avatar
babyjb1979
Helper I
3 years ago

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.

How can I do that? Really need help.

 

Thank you in advance!

Branko

2 Replies

  • 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)

     

     

    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

     

     

     

    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

     

     

     

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

     

     

    and not the same

     

     

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

     

    Regards

     

    Phil