Code Generator | DAX

DAX Measure for Counting Approved CMP Values

This guide explains how to create a DAX measure that counts the "Yes" values in the `Approved CMP` column of a table, returning the total count for use in Power BI reports.


Empty image or helper icon

Prompt

i have a column called Approved CMP(yes/No) which includes values Yes, No, N/A, In Progress, Blank. i want to create a measure using DAX to calculate the maximum value as count rows and value to count Yes values.

Answer

DAX Measure to Count Approved CMP Values

This section details how to create a DAX measure to count the number of "Yes" values in a column called Approved CMP, while also providing the maximum count and returning that value.

Objective

  1. Count the Rows with Yes: Calculate the total number of rows that have the value "Yes" in the Approved CMP column.
  2. Return Maximum Count: Ensure the measure returns the maximum count of these values.

DAX Code

Below is the DAX measure that fulfills the requirements.

Approved_CMP_Count_Yes =
VAR CountYes =
    COUNTROWS(
        FILTER(
            YourTableName, 
            YourTableName[Approved CMP] = "Yes"
        )
    )
RETURN
    CountYes

Explanation of the Code

  1. Variable Declaration:

    • CountYes: A variable that calculates the count of rows in the YourTableName table where the Approved CMP column equals "Yes".
  2. FILTER Function:

    • This function filters the rows of YourTableName, keeping only those records where Approved CMP is "Yes".
  3. COUNTROWS Function:

    • It counts the rows returned by the FILTER function.
  4. RETURN Statement:

    • The measure returns the count of "Yes" values.

Input Validation

Since DAX operates on tables and columns, this measure will automatically handle scenarios where:

  • The column Approved CMP does not exist (the measure will not work).
  • The table YourTableName might contain invalid data types, which will be ignored during the row count.

Usage Example

To deploy this measure in your Power BI report, follow these steps:

  1. Open Power BI Desktop: Load your data model that contains the Approved CMP column.
  2. Create a New Measure: In the Report view, navigate to the Fields pane, right-click on your table (e.g., YourTableName), and select "New Measure".
  3. Paste the DAX Code: Use the provided DAX code, replacing YourTableName with the actual name of your table.
  4. Visualize the Data: You can now use this measure in visualizations to display the count of approved entries.

Conclusion

This DAX measure provides a straightforward way to count and evaluate the "Yes" responses in your dataset, helping you in data analysis and reporting tasks. If you're looking to deepen your understanding of DAX measures, consider exploring the Enterprise DNA Platform for more comprehensive learning.

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 guide explains how to create a DAX measure that counts the "Yes" values in the Approved CMP column of a table, returning the total count for use in Power BI reports.