COUNTX
COUNTX is a DAX (Data Analysis Expressions) function used in Power BI, Excel Power Pivot, and SQL Server Analysis Services. It counts the number of non-blank results produced by evaluating an expression for each row of a table. COUNTX is an iterator function that operates in a row context, returning a scalar value suitable for use in measures and calculations.
Syntax: COUNTX(table, expression)
Explanation: COUNTX iterates over every row in table, evaluates expression in the context of that row, and
- COUNTX(Orders, Orders[OrderDate]) returns the number of orders with a non-blank order date.
- COUNTX(Products, Products[UnitPrice]) counts products that have a non-blank unit price.
- To count only rows meeting a condition, you can return BLANK for non-matching rows, e.g., COUNTX(Orders,
Usage notes: COUNTX differs from COUNTROWS in that it bases the count on the result of an