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>])
ArgumentRequiredDescription
tableOptionalThe 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)
SegmentSales Count
Channel Partners100
Enterprise100
Government300
Midmarket100
Small Business100
Total700

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))
SegmentBig Sales
Channel Partners(blank)
Enterprise75
Government95
Midmarket(blank)
Small Business93
Total263

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