Code Generator | DAX

Conditional Formatting DAX Function for Survey Data

This document details a DAX function to apply conditional formatting to the `rca-1` column in the `vw_RNTTP_SurveyCompletion` table, highlighting null values in red and inactive responses in gray based on `rca1enabled` status.


Empty image or helper icon

Prompt

table vw_RNTTP_SurveryCompletion column rca-1 format it to red if it is null and the value from column rca1enabled is 1 format it to gray if the value is 0

Answer

DAX Function for Conditional Formatting

This document outlines a DAX function designed to conditionally format the rca-1 column in the vw_RNTTP_SurveyCompletion table based on specific criteria related to the values in the rca1enabled column.

Function Overview

The function will:

  • Format values in the rca-1 column to red if they are NULL.
  • Format values to gray if the corresponding value in the rca1enabled column is 0.

Key Points:

  • Input: Data from the vw_RNTTP_SurveyCompletion table.
  • Output: Conditional formatting applied to the rca-1 column based on the specified criteria.

DAX Code Snippet

FORMAT_RCACOLOR = 
    VAR rcaValue = SELECTEDVALUE(vw_RNTTP_SurveyCompletion[rca-1])
    VAR rca1enabledValue = SELECTEDVALUE(vw_RNTTP_SurveyCompletion[rca1enabled])
    
    RETURN
        IF(
            ISBLANK(rcaValue) && rca1enabledValue = 1,
            "Red", 
            IF(
                rca1enabledValue = 0,
                "Gray",
                "DefaultColor" // Change this to your preferred default color
            )
        )

Function Logic:

  1. Variables:

    • rcaValue: Retrieves the value from the rca-1 column for the current row.
    • rca1enabledValue: Retrieves the value from the rca1enabled column for the current row.
  2. Conditional Logic:

    • The first condition checks if rcaValue is blank (NULL) and if rca1enabledValue is 1. If both are true, it returns "Red".
    • The second condition checks if rca1enabledValue is 0. If true, it returns "Gray".
    • If none of the conditions are met, it returns a default color (which you can customize).

Code Usage Example

To apply this function in your Power BI report or any DAX-compatible environment:

  1. Create a new measure in your data model.
  2. Copy and paste the above DAX code snippet into the measure's formula field.
  3. Use the measure for conditional formatting in your visuals.

Example Scenario

Assuming you have a report displaying survey completion statuses:

  • Survey Response: If a survey response in the rca-1 column is missing (i.e., NULL), and the survey is enabled (indicated by rca1enabled being 1), highlight that response in Red.
  • Inactive Survey: If rca1enabled equals 0 for any responses, color those entries in Gray.

Conclusion

Utilizing this DAX function will help in easily visualizing critical entries in your dataset according to specified parameters. For advanced DAX training and best practices, consider enrolling in courses on the Enterprise DNA Platform for further learning and development.

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 details a DAX function to apply conditional formatting to the rca-1 column in the vw_RNTTP_SurveyCompletion table, highlighting null values in red and inactive responses in gray based on rca1enabled status.