Forum Discussion

dokat's avatar
dokat
Post Prodigy
4 years ago
Solved

Conditional formatting with Dax

I have a measure i'd like to format background (not font) of the cell based on the value. I'd like to format background color based on below conditions. Can anyone help with below please?

 

if(and([NS Growth]<0,[Working Trade Rate Chg]<0,[NS Growth]<[Working Trade Rate Chg]),[NS Growth]/[Working Trade Rate Chg], Format Background in red,

if(and([NS Growth]<0,[Working Trade Rate Chg])>0),[NS Growth]/[Working Trade Rate Chg], Format Background in red,

if(and([NS Growth]>0,[Working Trade Rate Chg])<0),[NS Growth]/[Working Trade Rate Chg], Format Background in green,

if(and([NS Growth]<0,[Working Trade Rate Chg]<0,[NS Growth]>[Working Trade Rate Chg]),[NS Growth]/[Working Trade Rate Chg], Format Background in green)

  • dokat create a new measure, called "Background COlor" and then use this measure as conditional formatting using field value

     

    Background Color = 
    VAR __growth = [NS Growth]
    VAR __change = [Working Trade Rate Chg]
    RETURN
    SWITCH ( TRUE(),
    __growth <0 && __change<0 && __growth <__change, "Red", 
    __growth <0 && __change<0 && __growth >__change,"Green"
    __growth <0 && __change>0, "Red"
    __growth >0 && __change<0, "Green"
    )

     

    You can change the logic as you see fit, I guess this will give you an idea.

     

     

    Follow us on LinkedIn and  to our YouTube channel

     

    Learn about conditional formatting at Microsoft Reactor

    My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

     

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

2 Replies

  • dokat create a new measure, called "Background COlor" and then use this measure as conditional formatting using field value

     

    Background Color = 
    VAR __growth = [NS Growth]
    VAR __change = [Working Trade Rate Chg]
    RETURN
    SWITCH ( TRUE(),
    __growth <0 && __change<0 && __growth <__change, "Red", 
    __growth <0 && __change<0 && __growth >__change,"Green"
    __growth <0 && __change>0, "Red"
    __growth >0 && __change<0, "Green"
    )

     

    You can change the logic as you see fit, I guess this will give you an idea.

     

     

    Follow us on LinkedIn and  to our YouTube channel

     

    Learn about conditional formatting at Microsoft Reactor

    My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

     

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.