Should you use Measures for Conditional Formatting?
Wyn Hopkins
Solving data challenges for companies and people. Power BI | Excel | Fabric | Solver Budgeting & Consolidation. Part of the Amazing team at Access Analytic Microsoft MVP ??6 Million+ YouTube views
Streamline Your Power BI Conditional Formatting with Measures
I've always found the built-in conditional formatting in Power BI to be quite confusing. But check this out—you can use a measure for conditional formatting!
Wouldn't it be nice if you could change the color of all your visuals in one go? Well, you can!
Using Measures for Conditional Formatting
Here's how:
Color Red = "#df64550"
Color Green = "#36843a"
Finding those #Hex Codes: To find hex codes, you can go to View > Customize Current Theme in Power BI. Alternatively, I use Color Picker from PowerToys, a free Microsoft product. Just press Windows + Shift + C to pick colors from anywhere on your screen.
Create Conditional Formatting Rules:
Next, you’ll set up a conditional formatting rule.
Define the Rule:
领英推荐
cf rule Usage PY Variance =
VAR _Measure = [Usage v Prior Year]
VAR _Result=
SWITCH(
TRUE(),
_Measure >0, [ColourRed],
_Measure <0, [ColourGreen],
BLANK()
)
RETURN
_Result
You can adjust these conditions based on your specific needs.
Conditional Formatting in Visuals:
Go to the formatting pane and find the appropriate option (e.g., Callout Value for cards, Background Color for tables).
Clear any existing formatting and click on the FX button to set new formatting.
Choose the Field Value option and select the measure you created for conditional formatting
Final Thoughts
Are you already using this technique? Do you find it useful? Share any tips or pitfalls you've encountered in the comments.
Connect with me
The AA Team: Training and Consulting: https://accessanalytic.com.au/
Data Geek :: 3rd Dan Karate Instructor
9 个月The method I like is to use includes a couple of moving parts: 1. Customising the theme to align with the organisation brand, 2. A static table (JSON in PQ) detailing all the colours in this theme, plus any additional that may be required such as RAG tints (for backgrounds) or grey tints, 3. The name for each colour should be unique (even if the hex is not), 4. Create a measure for each required colour, 5. Should the organisation undergo significant re-branding, updating the JSON in the PQ informing the colours query will automatically update, and therefore wherever the data-driven measures are used in visual formatting the colours will magically update on refresh. 6. Levelling this up enterprise-wide would involve a shared semantic model comprising the endorsed "colours" table together with measures for each colour. I've not tested this for performance, but if branding & consistency is of high importance in your organisation, this is an approach to consider.
Business Intelligence Consultant | Power BI Developer | Apteco Accredited Trainer
9 个月I tend to do the same thing in all my reports. Gives me more control of things