Code Generator | Power BI

Power BI Conditional Formatting for RCA Column

This document outlines a DAX formula for Power BI to conditionally format the RCA column in the vw_RNTTP_SurveyCompletion table based on the state of rca1enabled and rcaenabled columns, enhancing report visuals.


Empty image or helper icon

Prompt

Table vw_RNTTP_SurveryCompletion column RCA 1 want to conditionally format them red if column rca1enabled equals 1 and they are null and gray is column rcaenabled equals 0

Answer

Power BI Conditional Formatting Function

This document outlines a DAX formula for Power BI that conditionally formats the RCA column in the vw_RNTTP_SurveryCompletion table based on the conditions specified regarding the rca1enabled and rcaenabled columns.

Function Overview

Purpose

To apply conditional formatting to the RCA column:

  • Format as red if rca1enabled is equal to 1 and RCA is null.
  • Format as gray if rcaenabled is equal to 0.

Input Parameters

  • vw_RNTTP_SurveryCompletion: The table containing the columns RCA, rca1enabled, and rcaenabled.

Return Type

  • This function returns a style format based on the conditions outlined.

DAX Code Implementation

Here is the DAX formula to achieve the required conditional formatting:

ConditionalFormattingRCA = 
VAR IsRCAEmpty = ISBLANK(vw_RNTTP_SurveryCompletion[RCA])
VAR Rca1Enabled = vw_RNTTP_SurveryCompletion[rca1enabled]
VAR RcaEnabled = vw_RNTTP_SurveryCompletion[rcaenabled]

RETURN 
    SWITCH(
        TRUE(),
        Rca1Enabled = 1 && IsRCAEmpty, "Red",       // Set red if rca1enabled is 1 and RCA is blank
        RcaEnabled = 0, "Gray",                    // Set gray if rcaenabled is 0
        "Default"                                  // Default for all other cases
    )

Explanation of the Code

  • Variables Defined:

    • IsRCAEmpty: Checks if the RCA column is blank.
    • Rca1Enabled: Stores the value of the rca1enabled column.
    • RcaEnabled: Stores the value of the rcaenabled column.
  • SWITCH Statement:

    • Evaluates the conditions in the order specified:
      1. If rca1enabled is 1 and RCA is blank, it returns "Red."
      2. If rcaenabled is 0, it returns "Gray."
      3. Otherwise, it defaults to "Default" (can be used to specify another color or state).

Usage Example

In your Power BI report, you can utilize this DAX function as conditional formatting in the Format pane of a Table or Matrix visual. Here’s the step-by-step approach to implement it:

  1. Add a New Measure:

    • Go to the Modeling tab and select New Measure.
    • Copy and paste the provided DAX function.
  2. Apply Conditional Formatting:

    • Select your visual that includes the RCA column.
    • In the Format pane, find the Conditional formatting section.
    • Click on Background color and choose Field value.
    • Select the measure ConditionalFormattingRCA.
  3. Save and Review:

    • Save changes and review the visual to verify that the formatting has been applied correctly based on the defined conditions.

Conclusion

This DAX function efficiently implements conditional formatting in Power BI to enhance the visual appeal and functionality of your reports. For further learning on DAX and advanced Power BI techniques, consider exploring the courses available on the Enterprise DNA Platform.

Create your Thread using our flexible tools, share it with friends and colleagues.

Your current query will become the main foundation for the thread, which you can expand with other tools presented on our platform. We will help you choose tools so that your thread is structured and logically built.

Description

This document outlines a DAX formula for Power BI to conditionally format the RCA column in the vw_RNTTP_SurveyCompletion table based on the state of rca1enabled and rcaenabled columns, enhancing report visuals.