How to Use COUNTIF in Power BI

Cody Schneider7 min read

If you're making the jump from Excel to Power BI, you might find yourself searching for a simple, familiar function: COUNTIF. While there isn't a DAX function with that exact name, you can achieve the same result - and much more - using a combination of other functions. This article will guide you through how to replicate COUNTIF in Power BI, starting with the basics and moving on to more powerful techniques.

Why Power BI Doesn't Have a Direct COUNTIF Function

First, it helps to understand why a direct COUNTIF replacement doesn't exist. In Excel, you work with cells and ranges. A formula like =COUNTIF(A2:A100, "Apparel") tells Excel to look at a specific, static grid of cells and count how many match your criteria.

Power BI thinks about data differently. It operates on a data model, using entire columns and tables, not static cell ranges. Instead of writing formulas that point to cells, you write Data Analysis Expressions (DAX) that operate on columns within tables. This approach is far more dynamic and powerful. When you click on a chart or apply a slicer, Power BI recalculates everything based on this new context dynamically. A static, cell-based function like COUNTIF just doesn’t fit this model.

The good news is that Power BI's method, while different, is incredibly flexible. The two key DAX functions you'll use to build your own COUNTIF are COUNTROWS and FILTER, often wrapped inside the powerhouse function, CALCULATE.

Your Go-To Method: Using COUNTROWS with FILTER

The most straightforward way to build a COUNTIF is by combining two simple DAX functions: COUNTROWS, which counts rows in a table, and FILTER, which creates a temporary table based on a condition you set.

The basic logic is:

  1. Use FILTER to generate a temporary, virtual table containing only the rows that meet your specific condition.
  2. Use COUNTROWS to count how many rows are in that temporary table.

The syntax looks like this:

Your Measure Name = COUNTROWS(FILTER('TableName', 'TableName'[ColumnName] = "Your Condition"))

An Example: Counting Sales by Region

Let's imagine you have a sales table named 'Sales' with columns like [Product], [Region], and [Sale Amount]. You want to count the total number of sales in the "North America" region. Here's how you'd do it step-by-step.

Step 1: Create a New Measure

In the Report view of an open Power BI desktop window, right-click on your 'Sales' table in the Data pane on the right-hand side. Select New measure.

This opens the formula bar at the top, where you'll write your DAX formula.

Step 2: Write the DAX Formula

In the formula bar, type the following:

North America Sales Count = COUNTROWS(FILTER('Sales', 'Sales'[Region] = "North America"))

Step 3: Understand the Formula

Let's break down what's happening:

  • FILTER('Sales', 'Sales'[Region] = "North America"): This part goes first. It examines your entire 'Sales' table, row by row. For each row, it checks if the value in the [Region] column is "North America." It then creates a new, temporary table in memory that includes only the rows that passed this test.
  • COUNTROWS(...): This function simply wraps around the FILTER logic and counts the number of rows present in the temporary table that FILTER produced.

After you press Enter to confirm the formula, you'll see your new measure appear in the Data pane, usually with a small calculator icon next to it.

Step 4: Visualize Your Measure

To see your result, you can drag the new "North America Sales Count" measure onto your report canvas. If you drop it onto a blank area, Power BI will usually create a Bar chart. To see the number clearly, select the visual and change its type to a Card in the Visualizations pane.

You’ve just successfully replicated COUNTIF!

Level Up with CALCULATE: The "Correct" Way in Power BI

While the COUNTROWS and FILTER combination works perfectly, Power BI experts will tell you that the most robust and efficient way to perform conditional calculations is with the CALCULATE function. Think of CALCULATE as the most important function in DAX. It modifies the "filter context," which essentially means it can change how a calculation behaves based on filters you provide directly in the formula.

The syntax looks slightly cleaner:

Your Measure Name = CALCULATE(COUNTROWS('TableName'), 'TableName'[ColumnName] = "Your Condition")

Let's rewrite our previous example using CALCULATE:

North America Sales Count (Calculate) = CALCULATE(COUNTROWS('Sales'), 'Sales'[Region] = "North America")

At first glance, this might not seem much different. However, here's why CALCULATE is preferred:

  • Readability: The logic is a bit easier to follow. "Calculate the row count for the Sales table, but only where the region is 'North America'."
  • Performance: On large datasets, CALCULATE can be more efficient than using FILTER as the base function.
  • Scalability: CALCULATE makes it incredibly easy to add more conditions, which we’ll cover in a moment.

For most of your COUNTIF-style calculations, using CALCULATE should be your default choice.

A Practical Guide to Common COUNTIF Scenarios

Now that you have the core concepts down, let's explore how to handle different types of conditions, just like you would in Excel.

1. Counting Based on Numeric Conditions (>, <, >=, <=)

You often need to count rows where a value is greater than or less than a certain number. Let’s count the number of high-value sales, which we'll define as any sale over $1,000.

High-Value Sales = CALCULATE(COUNTROWS('Sales'), 'Sales'[Sale Amount] > 1000)

You can use any of the standard comparison operators: > (greater than), < (less than), >= (greater than or equal to), <= (less than or equal to).

2. Counting Text Not Equal to Something

What if you want to count all sales that occurred somewhere other than "North America"? You can use the "not equal to" operator, which is <> in DAX.

Sales Outside North America = CALCULATE(COUNTROWS('Sales'), 'Sales'[Region] <> "North America")

3. Counting Rows Containing Specific Text

In Excel, you might use wildcards like "*laptop*" to count all cells containing the word "laptop". In DAX, you can achieve this with functions like CONTAINSSTRING().

Let’s say you want to count any sale where the [Product] name includes the word "Keyboard".

Keyboard Sales Count = COUNTROWS(FILTER('Sales', CONTAINSSTRING('Sales'[Product], "Keyboard")))

Note: For this specific task, it's often cleaner to stick with the FILTER approach, as embedding functions like CONTAINSSTRING directly into CALCULATE's filter area can behave unexpectedly for beginners.

4. Counting Blanks and Non-Blanks

To count rows where a column is empty, you can check for equality with the BLANK() function.

To count blank values: Let's find how many customers we have with a missing region entry.

Customers Missing Region = CALCULATE(COUNTROWS('Sales'), 'Sales'[Region] = BLANK())

To count non-blank values: You can count rows where the value is not blank.

Customers with Region Info = CALCULATE(COUNTROWS('Sales'), 'Sales'[Region] <> BLANK())

Beyond COUNTIF: Easily Replicating COUNTIFS

One of the biggest real-world benefits of using CALCULATE is how easily it handles multiple conditions, essentially replicating Excel's COUNTIFS function.

In Excel, you’d need a formula like =COUNTIFS(RegionRange, "North America", SalesRange, ">1000").

In DAX, you simply add each condition to your CALCULATE function, separated by a comma. Each new filter works as an "AND" condition.

Let's find the count of sales in "North America" that were also greater than $1,000.

High-Value North America Sales =

CALCULATE(

COUNTROWS('Sales'),

'Sales'[Region] = "North America",

'Sales'[Sale Amount] > 1000

)

As you can see, CALCULATE makes this incredibly clean and readable. You can add a dozen filters this way without making the formula messy or hard to follow.

Final Thoughts

While Power BI doesn't have a specific COUNTIF function, you can see that its tools for conditional counting are even more powerful. By combining COUNTROWS with FILTER or, more commonly, by using the versatile CALCULATE function, you can replicate any conditional counting scenario you handled in Excel and build dynamic, interactive reports that go far beyond what a static spreadsheet can offer.

Crafting DAX formulas and cleaning data are necessary steps in analysis, but we know your ultimate goal is to get insights, not to become a DAX programmer. At Graphed, we created our AI data analyst to streamline this entire process. We connect directly to your marketing and sales platforms, allowing you to ask questions in plain English - like "How many sales did we have in North America last quarter?" - and instantly receive the answer in a dashboard. This lets you focus on making decisions, not building reports.

Related Articles

How to Connect Facebook to Google Data Studio: The Complete Guide for 2026

Connecting Facebook Ads to Google Data Studio (now called Looker Studio) has become essential for digital marketers who want to create comprehensive, visually appealing reports that go beyond the basic analytics provided by Facebook's native Ads Manager. If you're struggling with fragmented reporting across multiple platforms or spending too much time manually exporting data, this guide will show you exactly how to streamline your Facebook advertising analytics.

Appsflyer vs Mixpanel​: Complete 2026 Comparison Guide

The difference between AppsFlyer and Mixpanel isn't just about features—it's about understanding two fundamentally different approaches to data that can make or break your growth strategy. One tracks how users find you, the other reveals what they do once they arrive. Most companies need insights from both worlds, but knowing where to start can save you months of implementation headaches and thousands in wasted budget.