Hex to R,G,B in Power Query (M Code)

Hello everyone I’m working on a project :

I got a table with two columns

Brand and Colors

Where some brands have mapped to them hex colors

Like :
Brand 1 → #000000
Brand 2 → null
Brand 3 → #000000
Brand 4 → #EFEFEF

and I want to be able to add 3 columns with the relative value of R , G , B.

That’s my first task to be able later to slightly change (for example) the value of G (like+1) in case of dupes for the color mapped to different brand ( to make it different by code but not noticeable by watching it )
And Then being able to change it back to Hex.

If you guys have alternatives I’m all ears!

Thanks !

Hi @tom071136 ,

If you looking for conversion algorithm you can find them at:

Good luck with your project.

1 Like

I think this M should do the conversion: InclusivePBI/PQ/fnGetRGBValue.pq at main · cbaragao/InclusivePBI (github.com)

This one should convert back: InclusivePBI/PQ/fnGetHexValue.pq at main · cbaragao/InclusivePBI (github.com).

I guess all you need now is to do the math in the middle.