TheColorAPI + PowerQuery = Color Scheme
I was looking at APIs and found a very cool one: The Color API. It is a nice API that does a lot of things, but one of its endpoints allows you to get a color scheme by passing a hex value and returning however many colors you want. Pretty sweet, right?
How could this be helpful? If you want to add some color to your report without generating a theme or referring to one declared, then this could be helpful.
The Code
Here is the code: PQ-Shared-Library/functions/UX/GetColorScheme.pq at main · cbaragao/PQ-Shared-Library (github.com)
There parameters are used:
- Hex – The hex code for the color that is your base (no hashtag needed as a prefix)
- Mode – The mode for generating the scheme
- 0 = monochrome
- 1 = monochrome-dark
- 2 = monochrome-light
- 3 = analogic
- 4 = complement
- 5 = analogic-complement
- 6 = triad
- 7 = quad
- Count = How many colors you want back
Calling it returns a table that looks something like this:
What was nice about the results here is that the API already figures out the closest color as well as the contrast you need for text.
My reaction was exactly this:
Wrap Up
I like trying to figure out UX issues like this and this would be a good one for a Custom Connector in Power Apps. This API is really simple and well done.
For now this is probably less useful, but still interesting to do. Also, it is a simple GET request and is good practice in terms of using URL parameters.
You can find this and other functions in the Power Query Shared Library: cbaragao/PQ-Shared-Library (github.com).
Also, if you would like to try it, I made prompted together an app that works with Power BI and helps a little with Power Query. You can find that here: cbaragao/GetPQ (github.com)
Comments are closed.