DAX COUNTROWS function
Counts the rows in a table.
COUNTROWS counts rows, which usually means counting events: orders, sales, tickets. It is the clearest way to count in DAX, because it doesn't depend on any one column being filled in.
Syntax
COUNTROWS([<table>])| Argument | Required | Description |
|---|---|---|
| table | Optional | The table to count, or an expression that returns a table, like FILTER(…). Without it, the home table of the measure is counted. |
Returns: A whole number. Blank if the table has no rows.
Examples
Calculated on the free practice data (table financials), with [Total Sales] = SUM(financials[Sales]) and [Total Profit] = SUM(financials[Profit]).
1. Number of sales by segment
Sales Count = COUNTROWS(financials)| Segment | Sales Count |
|---|---|
| Channel Partners | 100 |
| Enterprise | 100 |
| Government | 300 |
| Midmarket | 100 |
| Small Business | 100 |
| Total | 700 |
One row per sale, so this counts the sales in each segment.
2. Count only big sales
Big Sales = COUNTROWS(FILTER(financials, financials[Sales] > 100000))| Segment | Big Sales |
|---|---|
| Channel Partners | (blank) |
| Enterprise | 75 |
| Government | 95 |
| Midmarket | (blank) |
| Small Business | 93 |
| Total | 263 |
FILTER keeps the rows over 100,000; COUNTROWS counts what is left.
Good to know
- COUNTROWS returns blank, not 0, when nothing matches. Wrap it in COALESCE(…, 0) if a zero should show.
- Prefer COUNTROWS(table) to COUNT(column) for counting rows: it doesn't skip rows where that column is blank.
Related functions
Official reference: COUNTROWS function on Microsoft Learn