Short answer: use COUNTROWS ( table ) to count rows (orders, lines), and DISTINCTCOUNT ( column ) to count unique values (customers, products). COUNT counts non-blank values in a column (numbers, dates, strings), COUNTA also counts Booleans, and COUNTBLANK counts blanks. COUNTX and COUNTAX count the rows where an expression is not blank. DISTINCTCOUNTNOBLANK leaves BLANK out of the unique count, and APPROXIMATEDISTINCTCOUNT estimates it on very large DirectQuery data.
"How many customers bought?" and "how many orders?" are different counts, and so are "how many lines have a discount" and "how many customers have a discount". Picking the right function is most of getting them right.
What does each count?
| Function | Counts | Example |
|---|---|---|
| COUNTROWS ( table ) | rows of a table | COUNTROWS ( Sales ) |
| COUNT ( column ) | non-blank values: numbers, dates, strings | COUNT ( Sales[Ship Date] ) |
| COUNTA ( column ) | non-blank values, also Booleans | COUNTA ( Sales[Is Return] ) |
| COUNTBLANK ( column ) | blank cells | COUNTBLANK ( Sales[Ship Date] ) |
| COUNTX ( table, expr ) | rows where expr is not blank | COUNTX ( Customer, [Revenue] ) |
| COUNTAX ( table, expr ) | as COUNTX, counting any type of value | COUNTAX ( Sales, Sales[Comment] ) |
| DISTINCTCOUNT ( column ) | unique values, BLANK counted as one | DISTINCTCOUNT ( Sales[Customer Key] ) |
| DISTINCTCOUNTNOBLANK ( column ) | unique values without BLANK | DISTINCTCOUNTNOBLANK ( Sales[Promo Code] ) |
| APPROXIMATEDISTINCTCOUNT ( column ) | an estimate of unique values | APPROXIMATEDISTINCTCOUNT ( Events[User ID] ) |
When there are no rows to count, these functions return BLANK, not 0.
Which measures do you write most?
Orders = DISTINCTCOUNT ( Sales[Order ID] )
Order Lines = COUNTROWS ( Sales )
Customers = DISTINCTCOUNT ( Sales[Customer Key] )
Shipped Lines = COUNT ( Sales[Ship Date] )
Open Lines = COUNTBLANK ( Sales[Ship Date] )
Lines per Order = DIVIDE ( [Order Lines], [Orders] )
-- customers in the Customer table, whether they bought or not
Customers in List = COUNTROWS ( Customer )
-- customers with revenue over 10,000
Big Customers =
COUNTROWS ( FILTER ( VALUES ( Customer[Customer] ), [Revenue] > 10000 ) )
-- products sold in the period
Active Products = COUNTX ( VALUES ( 'Product'[Product] ), [Revenue] )Customers counts buyers in the current filter; Customers in List counts the dimension rows. On a page filtered to 2026, the first is "customers who bought in 2026", the second "all customers" (unless a filter reaches the Customer table).
Why does DISTINCTCOUNT not add up?
| Region | Customers |
|---|---|
| North | 120 |
| South | 95 |
| Sum of rows | 215 |
| Total | 214 |
The total counts the customer once. That is correct: a distinct count is never the sum of its parts. If readers expect the sum, add a note, or show "customer-region pairs" with SUMX ( VALUES ( Region[Region] ), [Customers] ).
When is an approximate count useful?
APPROXIMATEDISTINCTCOUNT returns an estimate of the distinct count and is meant for very large DirectQuery sources that can compute it faster. Microsoft marks support for it in Import and Direct Lake mode as preview. For most models, DISTINCTCOUNT is exact and fast enough.
What goes wrong?
COUNTon a key column with blanks. Rows with a blank key are not counted; useCOUNTROWSfor rows.COUNTROWS ( Customer )for buyers. It counts the dimension; buyers areDISTINCTCOUNTon the fact table's key.- DISTINCTCOUNT counting BLANK. A blank key counts as one value; use
DISTINCTCOUNTNOBLANKif it should not. - Showing 0. Counts return BLANK when nothing matches; that keeps empty rows out of visuals (see BLANK handling).
Where can you check this?
- Microsoft Learn: COUNTROWS function (DAX)
- Microsoft Learn: DISTINCTCOUNTNOBLANK function (DAX)
- Microsoft Learn: APPROXIMATEDISTINCTCOUNT function (DAX)
Where do you start?
Define Orders, Order Lines and Customers once, with these names, and build all other counts on them. SUM vs SUMX explains the iterator pattern behind COUNTX.