COUNT, COUNTROWS, DISTINCTCOUNT and more in DAX

Every DAX counting function compared, COUNT, COUNTA, COUNTBLANK, COUNTROWS, COUNTX, COUNTAX, DISTINCTCOUNT, DISTINCTCOUNTNOBLANK and APPROXIMATEDISTINCTCOUNT, what each counts, blanks, examples for orders, customers and active products, and which to use.

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?

FunctionCountsExample
COUNTROWS ( table )rows of a tableCOUNTROWS ( Sales )
COUNT ( column )non-blank values: numbers, dates, stringsCOUNT ( Sales[Ship Date] )
COUNTA ( column )non-blank values, also BooleansCOUNTA ( Sales[Is Return] )
COUNTBLANK ( column )blank cellsCOUNTBLANK ( Sales[Ship Date] )
COUNTX ( table, expr )rows where expr is not blankCOUNTX ( Customer, [Revenue] )
COUNTAX ( table, expr )as COUNTX, counting any type of valueCOUNTAX ( Sales, Sales[Comment] )
DISTINCTCOUNT ( column )unique values, BLANK counted as oneDISTINCTCOUNT ( Sales[Customer Key] )
DISTINCTCOUNTNOBLANK ( column )unique values without BLANKDISTINCTCOUNTNOBLANK ( Sales[Promo Code] )
APPROXIMATEDISTINCTCOUNT ( column )an estimate of unique valuesAPPROXIMATEDISTINCTCOUNT ( Events[User ID] )
DAX count functions

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?

RegionCustomers
North120
South95
Sum of rows215
Total214
Customers by region, one customer bought in two regions

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?

  • COUNT on a key column with blanks. Rows with a blank key are not counted; use COUNTROWS for rows.
  • COUNTROWS ( Customer ) for buyers. It counts the dimension; buyers are DISTINCTCOUNT on the fact table's key.
  • DISTINCTCOUNT counting BLANK. A blank key counts as one value; use DISTINCTCOUNTNOBLANK if 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?

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.

Keep reading

More from the blog.

Every post

Next

Building this? Say hello.

A question about this post, a pattern you would build differently, or the next thing you want written out: Behnia reads every message.