The COUNTX function counts the number of rows in a table for which the evaluation of an expression returns a number, a date, or a text.
COUNTX(
table,
expression
)
- table: Table containing the rows for which the expression will be evaluated.
- expression: Expression to evaluate for each row of the table.
The COUNTX function returns an integer.
The function evaluates the expression included as the second argument for each of the rows of the indicated table, returning the number of those rows that return numbers, dates or texts. If no rows are found, a Blank is returned. If rows are found but none satisfy the specified condition, a zero is returned.
To count logical values, the COUNTA or COUNTAX functions must be used.
The table argument can be either a table or a function that returns a table.
In this example we have a list of products that includes the price and the number of stocks of each one. If a product does not have a price assigned or the number of stocks is unknown, the table includes an empty cell:
We can count the number of products for which there is both an assigned price and a known stock with the following measure:
Número de productos = COUNTX(Productos, Productos[Precio] * Productos[Existencias])
...measure that, taken to a display of type "card", returns the following result: