Power BI COUNTIF

What is COUNTIF Function in Power BI?

The COUNTIF function in Power BI is a logical function that allows you to count the number of rows in a table or column that meet specific criteria. Unlike in Excel, the COUNTIF function is not a built-in function in Power BI. It is identical to the COUNTIF function in Excel, but it is specifically designed for use in Power BI to analyze and summarize data. Unlike Excel, Power BI doesn’t have any built-in COUNTIF function, however, there are similar functions or DAX expressions in Power BI to support the same logical function.

Key Takeaways
  • The COUNTIF function in Power BI allows you to count the number of rows in a table or column that meet specific criteria.
  • It is useful for analyzing and summarizing data based on certain conditions.
  • You can apply the COUNTIF function to tables or columns in Power BI.
  • The function can be combined with other functions and calculations to create more advanced measures and calculations.
  • If needed, the FILTER function can be used as an alternative approach to achieve similar results.

How to Use COUNTIF Function in Power BI?

Power BI has no built-in COUNTIF excel function for counting the number of records. Instead, there are multiple aggregate functions, such as COUNT, COUNTA, COUNTAX, or COUNTBLANK, to support similar functions.

Let’s see how we can apply the Power BI COUNTIF function using the COUNT function in Power BI using the steps provided below:

Step 1: Open Power BI Desktop and load your data source.

Step 2: Create a new measure or calculated column by right-clicking on the table or column where you want to apply the COUNTIF function and select New Measure or New Column.

Power BI Countif - Apply - Step 2

Step 3: In the formula bar, enter the following formula:

Power BI Countif - Apply - Step 3

Save this DAX expression by clicking on the Commit icon. It would create a new Count No of Customers measure in your data table. You can use this measure in your reports or analysis in Power BI.

As highlighted above, measures or columns can be created using various aggregate functions. Similarly, you can create and apply columns or CountIF measures based on multiple criteria and specific conditions.


Excel VBA – All in One Courses Bundle (35+ Hours of Video Tutorials)

If you want to learn Excel and VBA professionally, then ​Excel VBA All in One Courses Bundle​ (35+ hours) is the perfect solution. Whether you’re a beginner or an experienced user, this bundle covers it all – from Basic Excel to Advanced Excel, Macros, Power Query, and VBA.

Examples

In this section, we will apply countif functions to count the number of records in a column using COUNTA and COUNTAX functions.

Example #1 – Numbers of sales orders per state

In this example, we will apply the COUNTA excel function to calculate the number of sale orders per state using Sales Order data. 

Step 1: Create a new column of Count Sales Order on the Orders table either by choosing the New Column when you right-click on the financials table or the New Column option in the Modeling tab.

Here we have selected the latter option, as shown below.

Power BI Countif - Example 1 - Step 1

Step 2: Enter the column using the Power BI DAX expression in the formula bar and save the expression by clicking on the Commit icon.

Power BI Countif - Example 1 - Step 2

It will create a new column, Count of Sales Order in the Orders table visible in the Data pane.

Power BI Countif - Example 1 - Step 2 - Data pane

Step 3: Select this column and drag it to Canvas to create a report Statewise Sales Order Count in Power BI

Power BI Countif - Example 1 - Step 3

Alternatively, you can also calculate the Count of Sales Orders by choosing the Count option in the Visualization pane for the Order ID field. It doesn’t require any new column to be created.

Power BI Countif - Example 1 - Step 3 - Order ID

It will also provide the same result as the calculated column as shown below.

Power BI Countif - Example 1 - Step 3 - Table

Example #2 – Number of sales orders in the Corporate segment in California

Now, we will see how to apply the Countif function with the filter or multiple criteria conditions using the COUNTAX function. In this case, we will calculate the count of sales orders in the Corporate segment in California state using the Orders dataset as per the steps provided below:

Step 1: Import the Orders dataset through the Data Connection in Power BI. Right-click on the Orders table and select the New Column option to create a new column.

Power BI Countif - Example 2 - Step 1

Step 2: Enter the DAX expression for the new column in the formula bar and click on the commit icon to save it.

Power BI Countif - Example 2 - Step 2

In this DAX expression, we are creating a column on the Orders table that will store the total numbers of non-blank rows in the order id column in the Orders table for California state and in the corporate segment. It is achieved by applying Power BI filters on state and segment.

It will create a new column, Sales Order Count, in Corporate Segment in the Orders table.

Power BI Countif - Example 2 - Step 2 - Sales Order

Step 3: Drag the column to report canvas to create a visualization in Power BI.

Power BI Countif - Example 2 - Step 3

Alternative Method of COUNTIF Function

In Power BI, you can also achieve similar functionality as the COUNTIF function by using the COUNTROWS function. It allows you to count the total number of non-blank rows in a table. COUNTROWS function is more efficient and performs better than COUNT or COUNTBLANK functions and excludes any BLANK rows in any of the columns of a table.

To apply the COUNTROWS function, follow the steps mentioned below:

Step 1: Import the data to Power BI using a data connection.

Step 2: Create a new column by either right-clicking the table or choosing the New Column option in the Modeling tab.

In this case, we have opted for the right-click option to create the new column.

Alternative Method - Step 2

Step 3: Enter the DAX expression in the formula bar and click on the Commit icon to save

Alternative Method - Step 3

It will create a new column CountRows Orders, in the Orders table in the Data pane.

Alternative Method - Step 3 - Data pane

Step 4: Now drag the new column to report canvas to create visualizations in Power BI.

Alternative Method - Step 4

Important Things to Note

  • There is no built-in COUNTIF function in Power BI, however, there are other aggregate functions to perform similar functions.
  • The COUNT function only supports numbers, dates, or strings data types. A boolean data type is not supported in the COUNT function. It is, however, supported in the COUNTA function.
  • If you need to count cells containing any information or filter expression, it can be done with the COUNTAX function.
  • To calculate cells containing blank rows in a column, you can use the COUNTBLANK function, which works with all Power BI data types.
  • All the Count aggregate functions in Power BI are not supported for use in Direct Query mode for row-level security rules or calculated columns
  • Ensure that the data types of the columns and conditions are compatible to avoid errors or unexpected results.

Frequently Asked Questions (FAQs)

1. How do I count specific text in power bi?

To count specific text in Power BI, you can use the COUNTROWS function in combination with the FILTER function. It can be represented as below:
<Measure Name> = COUNTROWS (FILTER(<Table Name>,<Table Name>[<Column Name>] = “<Search Text>”))

FAQ 1

2. What are the limitations of Countif in Power BI?

The COUNTIF function is not a built-in function in Power BI, unlike in Excel. Instead, you can achieve similar functionality using the DAX (Data Analysis Expressions) language. However, there are certain limitations to consider when using Power BI COUNTIF or similar techniques in Power BI:
In Power BI, the equivalent DAX functions of COUNTIF such as COUNTX or CALCULATE, is powerful but may require more advanced DAX syntax to achieve complex conditions o Power BI COUNTIF Multiple Criteria.
By default, the DAX functions used in Power BI, including COUNTIF alternatives, are case-sensitive.
The calculation performance depends on the size of the data model and the efficiency of the DAX formula used in Power BI.
Power BI operates based on a data model that can have multiple tables and relationships between them.

3. Can you use Countif with symbols in Power BI?

When it comes to using symbols with Power BI COUNTIF-like functionality in Power BI, there are a few considerations:
Power BI supports limited wildcard functionality compared to Excel. The Power BI COUNTIF function in Excel allows wildcard characters like asterisks (*) and question marks (?) to match patterns in values. In Power BI, you can use the asterisk (*) as a wildcard character, but it may not work in all scenarios.
Power BI also supports regular expressions, which are powerful pattern-matching tools.
However, using regular expressions requires additional functions like REGEXMATCH.
When using symbols in COUNTIF-like operations, you need to be aware of their special meanings in DAX or the DAX functions you’re using.

4. Why is Countif in Power BI not working?

If the COUNTIF-like functionality in Power BI is not working as expected, there can be several reasons behind it. Here are a few common issues and potential solutions:
Syntax or formula error: Make sure you are using the correct DAX functions and operators.
Ensure that the data types of the column you’re counting and the criteria you’re using in the COUNTIF-like operation are similar.
If you’re performing the COUNTIF-like operation across different tables, ensure that the relationships and column references are properly defined.
Aggregation and summarization: Ensure that you are applying appropriate aggregation functions (e.g., SUM, COUNT, AVERAGE) to the column you’re counting in Power BI.
Refresh and data model issues: Ensure you have refreshed the dataset in Power BI after any changes to a data sources or data model.

This has been a guide to Power BI COUNTIF. Here we learn how to use COUNTIF formula in Power BI with examples and downloadable template. You can learn more from the following articles –

Reader Interactions

Leave a Reply

Your email address will not be published. Required fields are marked *