Forum Discussion
Reference theme dataColors with DAX
As a developer I want to be able to reference data colour hex codes via Dax. I can reference Divergent and Sentent colors but nothing else.
The reason I want to do this is to help me create templates that have page titles and use colors from the theme. What would be better would be to add three layers of color codes that can be used for branding of the reports.
Hi TrevorC - Power BI doesn’t currently expose all theme color hex codes directly to DAX, which limits dynamic formatting and templating potential.
Good Idea, : you can post it in below link:
Fabric Ideas - Microsoft Fabric Community
Hope this helps.
7 Replies
- TrevorCAdvocate I
Hi there.
The folks at SQLBI.com have found a way to read some of the color codes.
Re-using visual formatting in and across Power BI reports - SQLBICombining the two approaches: referencing theme colors from DAX
Now, how do we use this with our themes? Well, it turns out that you can refer to theme colors from DAX. Like CSS color names, any top-level theme property that is a color can be used in a DAX expression. Examples include:
- Sentiment colors: “good”, “bad”, or “neutral”, which refer to positive, negative, and neutral sentiment theme colors, respectively.
- Diverging colors: “minColor”, “midColor”, or “maxColor”, which refer to min, middle, and max diverging theme colors, respectively.
- Container style colors: “foreground”, “background”, or “foregroundNeutralTertiary”, which refer to various elements as explained in the documentation for theme structural colors.
- Other structural colors: “tableAccent”, “null”, or “hyperlink”, which refer to the border of the table or matrix visual, empty colors in diverging conditional formatting, and the color of hyperlinks in tables and matrix visuals, respectively.
- v-sshirivoluCommunity Support
Hi TrevorC ,
Thanks for sharing the SQLBI reference. This helps clarify the behavior. While Power BI still doesn't expose the full dataColors array to DAX, it does allow referencing certain top level theme colors using predefined names, such as sentiment, diverging, and structural colors. So only these specific theme color tokens are available in DAX today. If full control over colors is needed, a disconnected color table remains the recommended approach.
- rajendraongole1Super User
Hi TrevorC - Power BI doesn’t currently expose all theme color hex codes directly to DAX, which limits dynamic formatting and templating potential.
Good Idea, : you can post it in below link:
Fabric Ideas - Microsoft Fabric Community
Hope this helps.
- v-sshirivoluCommunity Support
Hi TrevorC ,
At this time, Power BI does not provide direct access to all theme color hex codes (dataColors) within DAX. You may wish to submit this as a feature request or upvote an existing idea using the link provided.
Fabric Ideas - Microsoft Fabric CommunityAs a workaround, you can create a disconnected color table with category–color mappings and use a measure like below for conditional formatting:
Color Code =
LOOKUPVALUE(
ColorTable[ColorHex],
ColorTable[Category],
SELECTEDVALUE(Data[Category])
)Then apply this measure in the Field value option under conditional formatting to get theme based colors.
- v-sshirivoluCommunity Support
Hi TrevorC ,
I hope the information provided above assists you in resolving the issue. If you have any additional questions or concerns, please do not hesitate to contact us. We are here to support you and will be happy to help with any further assistance you may need.
- v-sshirivoluCommunity Support
Hi TrevorC ,
I hope the above details help you fix the issue. If you still have any questions or need more help, feel free to reach out. We’re always here to support you
- KNPSuper User
Hi TrevorC,
As others have mentioned, not all colours are exposed currently.
Best practice at the moment would be to have a colour table that can be imported into your models and reference HEX/RGBA colours from there. It allows for use in conditional formatting, etc., and as long as your theme colours are constant, it is easy to match your theme.
Bonus points for creating an opposing text colour, taking into account contrast ratios.