jeudi 4 avril 2019

DAX, Using Colors names instead of Hex Code


Yesterday, I read a blog post from Matt Allington where he presented a way to apply conditional formatting with a Text field (not a numeric field) "Conditional Formatting with a Text Field in Power BI".

I really loved the possibility of using Color names, in DAX Measures, instead of Hex code, but a question remained "Is there a list of all valid colors names that I can use in DAX Measures?"

After some search on the web I was not able to find that list. So, I started to randomly try some colors names, I found on web pages like "99Colors" or "Farb-Tabelle", some of them worked but not the majority and what I ended up with is that:
  • A valid name must not contain spaces."DarkBlue" is valid but not "Dark Blue".
  • The color name is not case sensitive DarkBlue and darkblue both will work.
  • ALL the basic colors (black, red, green, …) worked find.
This last point, and because I'm coming from Excel, give me an idea, why not trying the Excel colors enumeration known as XLRgbColors and guess what, all of them worked fine except "NavyBlue".

Continuing my tests, I find that:
  • Some colors have two names, Gray and Grey, DarkGray and DarkGrey, DarkSlateGray and DarkSlateGrey, DimGray and DimGrey, LightGray and LightGrey, LightSlateGray and LightSlateGrey.
  • NavyBlue is listed with another name which is Navy.
  • Five other colors worked for me event if they are not listed in the XLRgbColor Enumeration, Magenta (listed as Fuchsia) Cyan (listed as Aqua), Chocolate, Rebecca Purple and SaddleBrown so maybe you will be able to find more colors that work just let me know.
Now I have a list of 148 colors names that I can use in DAX measures instead of hex code and you can find them by downloading this .csv file by following this link.

PS: I finally was able to figure out what is the reference for that names list and it is the CSS3 Color Names.

#powerbi #dax

Aucun commentaire:

Enregistrer un commentaire