Downloads
DAXAggregationBeginner

COUNTROWS

Counts the rows in a table.

Syntax
COUNTROWS(<table>)

Returns: A whole number (a scalar).

What it does

COUNTROWS counts the rows of a table that are visible in the current filter context. It counts rows, not values, so a row with blanks in every column still counts. It is the standard way to count transactions, invoices, orders or journal lines. Pass it a filtered table to count only the rows that meet a condition.

Syntax and arguments

Example

The operations manager wants the number of sales transactions in the selected period, to compare with the number of orders shipped.

Sales Lines = COUNTROWS(Sales)

Under a date slicer for one quarter, the measure counts the lines in that quarter. Placed next to Total Sales, it shows the average value per line when divided with DIVIDE.

Example: a second, different use

Count the customers who bought in the period, using a table of distinct customers:

Active Customers =
COUNTROWS(
    FILTER(
        VALUES(Sales[CustomerKey]),
        [Total Sales] > 0
    )
)

VALUES gives one row per customer, and FILTER keeps the customers with positive sales. COUNTROWS then counts them. This is a count of distinct customers, which a plain COUNTROWS(Sales) is not.

Things to watch

In business terms

COUNTROWS is the first measure most finance teams build: number of invoices, number of journal lines, number of payroll records, number of open tickets. It is also the basis of average transaction size, which is total divided by this count.

Related functions

All DAX functions · View as Markdown · DAX fundamentals