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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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