Power BI DAX COUNTIF: How to Count Rows Conditionally
In this article
Power BI DAX has no COUNTIF function. Instead, you use CALCULATE together with COUNTROWS to count rows that meet one or more conditions. For example, Active Customers = CALCULATE(COUNTROWS(Customers), Customers[Status] = "Active") returns the number of active customers. This guide shows the exact patterns for counting rows, counting non-blank values, and counting with multiple filters, plus how to avoid the most common errors.
What You'll Need
- Power BI Desktop (any recent version) with a data model loaded.
- A table and at least one column you want to filter on.
- Basic familiarity with the formula bar and the Fields pane.
Step-by-Step
- Open a new measure. In the Home ribbon, click New Measure. The formula bar appears. Measures are the right place for conditional counts because they respond to slicers and filters.
- Start with CALCULATE and COUNTROWS. Type
MyCount = CALCULATE(COUNTROWS(Sales)). This counts all rows in the Sales table, but it is not yet conditional. - Add a single filter. Inside CALCULATE, after the COUNTROWS argument, add a comma and a Boolean filter:
MyCount = CALCULATE(COUNTROWS(Sales), Sales[Region] = "North"). The measure now counts only rows where Region is North. - Add multiple filters. Separate each condition with a comma:
MyCount = CALCULATE(COUNTROWS(Sales), Sales[Region] = "North", Sales[Amount] > 100). All conditions must be true (AND logic). - Use OR logic when needed. Wrap conditions in
FILTER:MyCount = CALCULATE(COUNTROWS(Sales), FILTER(Sales, Sales[Region] = "North" || Sales[Region] = "South")). The double pipe||means OR. - Count non-blank values instead of rows. If you want to count how many rows have a value in a column (ignoring blanks), use
COUNTA:MyCount = CALCULATE(COUNTA(Sales[CustomerID]), Sales[Region] = "North"). For distinct counts, useDISTINCTCOUNTthe same way. - Reference a slicer or date table. Replace the hard-coded filter with a column from a related table, for example
CALCULATE(COUNTROWS(Sales), Dates[Year] = 2024). Relationships must exist and be active. - Format and test. Select the measure, set the format to Whole Number in the Modeling tab, then drop it into a card visual. Add a slicer on Region and confirm the number changes as expected.
Menu labels can differ slightly by Power BI Desktop version and region, but the formula patterns above are stable.
Common Mistakes
- Using COUNTIF. DAX does not have COUNTIF; the formula bar will flag it as an unknown function. Use CALCULATE + COUNTROWS instead.
- Filtering the wrong table. If you filter a lookup table but count rows in a fact table, the relationship direction matters. Filter the table you are counting, or ensure the relationship propagates the filter.
- Using = instead of == in comparisons. In DAX,
=is both assignment and comparison; inside CALCULATE filters it works as comparison. But in some contexts, especially with variables, use==for clarity. The common error is mixing up the two and getting a syntax error. - Forgetting that CALCULATE overrides filters. A filter inside CALCULATE replaces existing filters on the same column. If you need to keep the outer filter, use KEEPFILTERS.
- Counting blanks. COUNTROWS counts all rows, including those with blank values. If you need non-blank counts, use COUNTA or COUNT.
Tips
- Use variables to make complex measures readable:
VAR FilteredRows = FILTER(Sales, Sales[Amount] > 100) RETURN CALCULATE(COUNTROWS(Sales), FilteredRows). - For a quick conditional count without writing DAX, add the column to a visual and use the visual-level filter. But a measure is reusable across pages.
- Use
TREATASwhen you need to apply a filter from an unrelated table. - Name measures clearly, e.g., Orders Over 100, so report users understand what is counted.
Troubleshooting
- The measure returns blank. Check that the filter column exists in the table you are counting, or that a relationship is active. Also confirm the filter value matches exactly (case-sensitive in some sources).
- The number does not change with slicers. The measure may be hard-coded to ignore filters. Remove any ALL or REMOVEFILTERS inside CALCULATE, or check that the slicer field is in the same table or a related table.
- Error: “The name 'COUNTIF' isn't recognized.” Replace with CALCULATE(COUNTROWS(...)).
- Performance is slow. Avoid using FILTER over large tables when a simple Boolean filter works. Prefer
CALCULATE(COUNTROWS(Sales), Sales[Region] = "North")overCALCULATE(COUNTROWS(Sales), FILTER(Sales, Sales[Region] = "North"))when possible. - If that did not work, check the data type of the filter column. Comparing text to a number will return no rows. Use VALUE() or adjust the literal.
Frequently Asked Questions
Is there a COUNTIF function in DAX?
No. DAX uses CALCULATE with COUNTROWS or COUNTA to achieve conditional counts. COUNTIF exists in Excel, not in DAX.
How do I count rows with multiple conditions in DAX?
Add each condition as a separate argument inside CALCULATE: CALCULATE(COUNTROWS(Table), Table[Col1] = "A", Table[Col2] > 10). All conditions are combined with AND.
Can I count distinct values conditionally?
Yes. Use CALCULATE(DISTINCTCOUNT(Table[Column]), Table[Filter] = "Value"). This counts unique non-blank values that meet the filter.
Why does my measure ignore slicers?
You may have used ALL or REMOVEFILTERS inside CALCULATE, which clears filters. Remove those functions or use KEEPFILTERS to preserve the slicer context.
What is the difference between COUNTROWS and COUNTA?
COUNTROWS counts all rows in a table, including those with blanks. COUNTA counts non-blank values in a column. Use COUNTA when you want to exclude blanks.
Can I use COUNTIF with a date range?
Yes. Use . Ensure the date column is of type Date.