Forum Discussion

c_banerjee's avatar
c_banerjee
Frequent Visitor
1 month ago
Solved

Conditional formating using DAX

i have created a dax measure to apply conditional formatting however i have the conditions written, but i dont see conditional format anywhere.

Margin Color =
VAR m = SELECTEDVALUE(Total_Sales[Margin])
RETURN
SWITCH(
    TRUE(),
    m < .40, "Orange",  
    m < .50, "Red",  
    m < .60, "Light Green",  
    "Dark green"             
)

However, now that I have the measure, I'm unable to apply it to my margin. I don't know where to find the conditional formatting option or what to do. I could use Microsoft's built-in cell elements, but I don't want to use that; I want to use the DAX condition I created. Where can I find the correct tab to apply my measure?

Thank you
  • c_banerjee Same measure mentioned I have used for checking Sales in below table and added conditional formatting to Region as below - 

     

    πŸ’‘ Helpful? Give a Kudos πŸ‘ β€” keep the community growing
    βœ… Solved your issue? Mark as Solution βœ”οΈ β€” help others find it faster

    Best regards,
    Rupasree Achari | BI & Fabric Analytics Engineer   

9 Replies

  • Rupa01's avatar
    Rupa01
    Solution Sage

    Hi c_banerjee

    Follow below steps to add conditional formatting -

    1. Select the visual and go to Visual formatting Pane > Cell Elements

    2. Select the column/field you want to apply conditional formatting

    3. Toggle "On" Background color or font color based on your requirement.

    4. A window opens to select the colour options, Select "Field Value" under Format style and select measure created under "What field should we base this on?" (in your case - Margin Color). Click Ok and conditional formatting is applied to the filed choosen.

     

    Sample Example Result - I have applied background color for State column based on Measure.

     

    πŸ’‘ Helpful? Give a Kudos πŸ‘ β€” keep the community growing
    βœ… Solved your issue? Mark as Solution βœ”οΈ β€” help others find it faster

    Best regards,
    Rupasree Achari | BI & Fabric Analytics Engineer 
    • Rupa01's avatar
      Rupa01
      Solution Sage

      c_banerjee Same measure mentioned I have used for checking Sales in below table and added conditional formatting to Region as below - 

       

      πŸ’‘ Helpful? Give a Kudos πŸ‘ β€” keep the community growing
      βœ… Solved your issue? Mark as Solution βœ”οΈ β€” help others find it faster

      Best regards,
      Rupasree Achari | BI & Fabric Analytics Engineer   
      • c_banerjee's avatar
        c_banerjee
        Frequent Visitor

        hi Rupa01 
        But now the issue whole column is orange, what im doing wromg here, is there any problem with measure margin color? or measured column total_sales[margin]

  • For a table or matrix visual:

    Select your table or matrix visual.
    In the Visualizations pane, go to the Values section.
    Find the Margin field.
    Click the dropdown arrow next to the Margin field.
    Select Conditional formatting.
    Choose Background color or Font color.
    In the dialog box, set Format by to Field value.
    In Based on field, select your measure Margin Color.
    Click OK.

    For a chart (bar, column, etc.):

    Select the chart visual.
    Open the Format pane.
    Expand the Data colors section.
    Click the Advanced controls or fx option.
    Set Format by to Field value.
    Select your measure Margin Color.
    Apply the changes.

    Important note:
    Make sure your measure returns valid color values such as Red, Green, or hex codes like #FF0000.



    • c_banerjee's avatar
      c_banerjee
      Frequent Visitor

      there is format ,build and data pane, format pane has visual and properties, i didnot find anything called data colors, however there is a cell element which has background color selected fx, selected field value  what field should we base this on selected margin color.. what why everything is orange!

  • Hi,

    Your DAX measure looks fine, but whether you can use it for conditional formatting depends on the visual you're using.

    A few things to check:

    • Make sure you're using a visual that supports conditional formatting (such as a Table or Matrix).

    • Select the visual, then in the Values well, click the drop-down arrow next to the Margin field and look for Conditional formatting (or Cell elements in newer versions of Power BI).

    • Choose Background color or Font color, then select Format by β†’ Field value and choose your Margin Color measure.

    If you don't see the Conditional formatting option:

    • Verify that you're using a Table or Matrix visual, as not all visuals support field-value formatting.

    • Ensure the measure returns valid color names (e.g., "Red", "Orange") or hexadecimal color codes (e.g., #FF0000), which are generally more reliable.

    • Confirm that the field you're formatting is in the Values section of the visual.

    Could you let us know:

    • Which visual are you using (Table, Matrix, Card, etc.)?

    • Which version of Power BI Desktop are you using?

    • Are you trying to color the text, the background, or something else?

    The Microsoft documentation on conditional formatting may also help:
    https://learn.microsoft.com/power-bi/create-reports/desktop-conditional-table-formatting

    If you found this reply helpful, please consider giving it a Kudos. If it helps resolve your issue, marking it as the Accepted Solution will help others facing the same problem.

  • v-abhinavmu's avatar
    v-abhinavmu
    Community Support

    Hi c_banerjee,

    I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. 


    Thank you.