Forum Discussion

MChakri's avatar
MChakri
Regular Visitor
3 years ago

Conditional Formatting - Switch Case

Hello Pals,

 

I have a peculiar case with Switch statement as I am unable to apply conditional formatting for a single line item. Lets say, I have 5 line items and calculated against months like JAN, FEB, ...DEC, Q1, Q2, Q3, Q4, YTD etc..,I have a Grand total as 5th line item and that line item need to have a conditional formatting for "-" values. (Identified with a different color instead of default).  

 We would like to see the conditional formatting for Total other Margin and Net Margin should be with different color in Power BI. 

 

Switch statement looks like the above 

10 Replies

  • Akshaan's avatar
    Akshaan
    Frequent Visitor

    Hi MChakri, you can achieve this by using a similar dax measure only for a selected dimension ( in your case line 5 item). 

     

     

    if it doesn't works for you, please share your .pbix file.

    • MChakri's avatar
      MChakri
      Regular Visitor

      Hi Akshaan, Is this possible for only negative values...This should work if we have any negative values in the "Net Margin" column alone. Apologies for my late response.. Wanted to share the .pbix file but I don't see an option to do so. 

       

  • Akshaan's avatar
    Akshaan
    Frequent Visitor

    Hi MChakri you can make this small change to get the desired result.


    Please accept this as solution if it works for you to help others.

    Thanks,

    • MChakri's avatar
      MChakri
      Regular Visitor

      Pls correct me If I am wrong in above!!Akshaan , see this is not working for me. One thing is that this is a derived field !! Pls correct me!

      • Akshaan's avatar
        Akshaan
        Frequent Visitor

        Hi MChakri , it seems you are not passing the condition for CategoryIntern column in the above measure (line 5 item). Also, can you please explain why are you using 2 different measures in here?
        1.  NETMARGIN- YTD

        2. OTHER COGS Test


        You can share you .pbix frm here.

         

    • Akshaan's avatar
      Akshaan
      Frequent Visitor

      Hi MChakri, This is the answer to the above asked question:

      CF =
      SWITCH(
          SELECTEDVALUE('New Table'[Report Column]),
          "Other: Audit Accruals/Credits Margin" , IF([JANNEWF]<0, "Red")
      )

      Here are my observations/suggestions:
      1. Use hierarchies instead of calculated column Categorn intern with some additional spaces
      2. You derived field i.e. JANNEWF , FEBNEWF should be in Whole Number format instead of text to make this code work.