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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
bvy
Helper V
Helper V

Need a nifty measure that will set Font Color based on Background Color...

Quite simply I have a value in my data model called ColorRGB that returns a color value in this form: 

 

RGB(222, 0, 222)

 

I use this to conditionally format the the background color of a card visual (First - Field Value, and select ColorRGB).

 

What I need is a measure that can read the color in that format, and return either black or white depending on the background color (white for darker colors, black for lighter colors). I'm trying to avoid parsing the RGB values out of that string, hoping there's an easier way. Obviously I want to also conditionally set the font color so it shows up with some contrast against whatever background color is being displayed. 

 

Thanks! 

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @bvy 

 

Using color strings like that I think you will have the parse the string to figure out what color it is.

 

But you can use known CSS color names in your CF

 

CSS Color Names (w3docs.com)

 

Using these will make it a lot easier to know what color is being applied to the BG as you just need to check for specific color names e.g. "red", "firebrick" etc.

 

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!


View solution in original post

1 REPLY 1
PhilipTreacy
Super User
Super User

Hi @bvy 

 

Using color strings like that I think you will have the parse the string to figure out what color it is.

 

But you can use known CSS color names in your CF

 

CSS Color Names (w3docs.com)

 

Using these will make it a lot easier to know what color is being applied to the BG as you just need to check for specific color names e.g. "red", "firebrick" etc.

 

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!


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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