The COUNTROWS function counts the number of rows in a table.
COUNTROWS(
<table>
)
- table: Name of the table whose rows we want to count or expression that returns a table.
The COUNTROWS function returns an integer.
If the table does not contain any rows, a BLANK value is returned. It should be noted that, for the calculation, the function is contextualized. That is, it does not calculate, in the strict sense of the term, the number of rows in the table, but rather the number of rows in the table once the corresponding context is applied to it.
In this example we want to know the number of rows contained in the FactSales table, for which the following measure is defined:
NumVentas = COUNTROWS(FactSales)
If the result is shown in a "card" type display, we get the following:
If we have in FactSales a list of sales (each row corresponding to a sale) and we define the following measure:
Nº de ventas = COUNTROWS(FactSales)
...we can create a matrix to take the years and the newly created measure to. As seen in the following image, the measure is contextualized for each year: