COUNTROWS DAX Function (Aggregation)

Counts the number of rows in a table.

Syntax

COUNTROWS ( <Table> )
Parameter Attributes Description
Table

The table containing the rows to be counted.

Return values

Scalar A single integer value.

Number of rows obtained by the evaluation of the table expression. If the table has no rows, it returns blank.

Remarks

This function can be used to count the rows of a table expression.

Examples

The following are valid syntaxes.

COUNTROWS ( table )
COUNTROWS ( DISTINCT ( table ) )
COUNTROWS ( VALUES ( table ) )

The COUNTROWS function can be used to count the unique values available in a column for the current filter context. However, DISTINCTCOUNT is better in that case. The following expressions are equivalent.

COUNTROWS ( DISTINCT ( table[column] ) )
DISTINCTCOUNT ( table[column] ) )

The COUNTROWS function can be used to check whether a column has only one item filtered/selected in the current filter context. However, HASONEVALUE is better in that case. The following expressions are equivalent.

COUNTROWS ( VALUES ( table[column] ) ) = 1
HASONEVALUE ( table[column] ) )

Related articles

Learn more about COUNTROWS in the following articles:

Related functions

Other related functions are:

Last update: Oct 20, 2018   » Contribute   » Show contributors

Contributors: Alberto Ferrari, Marco Russo

MSDN documentation: https://msdn.microsoft.com/en-us/query-bi/dax/countrows-function-dax

DAX Conventions
Context Transition

This function performs a Context Transition if called in a Row Context. Click to read more.

Row Context

This expression is executed in a Row Context. Click to read more.

Not recommended

The use of this function is not recommended. See Remarks and Related functions for alternatives.

Not recommended

The use of this parameter is not recommended.

Deprecated

This function is deprecated. Jump to the Alternatives section to see the function to use.

Deprecated

This parameter is deprecated and its use is not recommended.

Contribute

Want to improve the content of COUNTROWS? Did you find any issue? Please, report it us!
All submissions will be evaluated for possible updates of the content.