Should you use Measures for Conditional Formatting?

Should you use Measures for Conditional Formatting?

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:

  1. Set Up Base Measures: Start by creating two base measures:

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:

  • For a measure evaluating variance, such as "Usage vs. Prior Year," you can set the rule as follows:
  • If the value is greater than zero, apply the red color.
  • If the value is less than zero, apply the green color.

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:

  • Select the visual you want to format.

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

https://www.dhirubhai.net/in/wynhopkins/

https://wyn.bio.link/

The AA Team: Training and Consulting: https://accessanalytic.com.au/

Bettina Ellis-Klar

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.

Antony C.

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

要查看或添加评论,请登录

Wyn Hopkins的更多文章

  • The Best Dependent Drop Down Technique

    The Best Dependent Drop Down Technique

    Driven by a gauntlet laid down by friend and fellow MVP Mark Proctor on our Unpivot podcast recently I revisited my…

    1 条评论
  • Consolidate and Hyperlink to Excel files on SharePoint

    Consolidate and Hyperlink to Excel files on SharePoint

    In this video, we're diving into the world of Excel and Power BI, focusing on creating hyperlinks for easy referencing…

    4 条评论
  • The greatest multi-level Excel drop-down list ever!

    The greatest multi-level Excel drop-down list ever!

    One-Off dependent drop down lists in data validation are relatively straightforward: here's a technique using XLOOKUP…

    5 条评论
  • Default Your Slicer to the Current Month in Power BI

    Default Your Slicer to the Current Month in Power BI

    First Published November 2022 on our YouTube Channel Join 65,000+ subscribers to stay up to date with new videos…

    4 条评论
  • Power BI Licensing Explained

    Power BI Licensing Explained

    What are the differences between: Power BI Free (soon to be renamed Fabric Free) Pro: $10 USD pp/pm PPU (Premium Per…

    2 条评论
  • Power BI May 2023 Release

    Power BI May 2023 Release

    The May version of Power BI desktop is out This is a very quick post highlighting my 2 favourite picks: 1. Azure Maps…

    5 条评论
  • Simpler DAX ? = Power Query

    Simpler DAX ? = Power Query

    If you are struggling to write a complicated DAX formula then the answer may be to step back and do a little Power…

    2 条评论
  • Power BI Explained

    Power BI Explained

    A simple explanation of Power BI I hope you find this useful. Power BI continues to go from strength to strength and…

  • SUMX explained.

    SUMX explained.

    SUMX is a DAX function that can be used in an Excel Data Model (aka Power Pivot) to create a temporary column…

    6 条评论
  • XLOOKUP v Power Query v Power Pivot

    XLOOKUP v Power Query v Power Pivot

    When combining tables in Excel there are several options. In this video I show you XLOOKUP, Power Query Merge and a…

    5 条评论

社区洞察

其他会员也浏览了