"How many orders?", "How many customers?", "How many products sold at least once?" Counting looks simple, but DAX has several counting functions and picking the wrong one gives numbers that are too high, or totals that look broken. This guide explains COUNT, COUNTROWS, DISTINCTCOUNT and their relatives with real Power BI measures.
Quick answer
| Function | Counts | Typical use |
|---|---|---|
COUNTROWS(table) | Rows of a table | Number of transactions or order lines |
COUNT(column) | Non-blank values in a column | Rows where a value is filled in |
COUNTA(column) | Non-blank values, any type (including TRUE/FALSE) | Same as COUNT for most columns |
COUNTBLANK(column) | Blank values | Data-quality checks |
DISTINCTCOUNT(column) | Unique values (a blank counts as one value) | Customers, orders, products |
DISTINCTCOUNTNOBLANK(column) | Unique values, ignoring blank | Unique counts on columns with gaps |
The examples use a Sales table with one row per order line: OrderID, CustomerID, ProductID, Region, Date, Amount, and a Customer table.
COUNTROWS: count rows
Order Lines = COUNTROWS ( Sales )
Counts every row in the current filter context. It is the clearest and usually the fastest way to count rows. Prefer it over COUNT ( Sales[OrderID] ) when you simply want rows, because COUNTROWS does not depend on whether a particular column has blanks.
COUNT: count filled-in values
Lines with Discount = COUNT ( Sales[Discount] )
Counts rows where Discount is not blank. Use it when "filled in" is what you want to measure.
DISTINCTCOUNT: count unique values
Orders = DISTINCTCOUNT ( Sales[OrderID] )
Customers = DISTINCTCOUNT ( Sales[CustomerID] )
Products Sold = DISTINCTCOUNT ( Sales[ProductID] )
If one order has three lines, COUNTROWS gives 3 but DISTINCTCOUNT on OrderID gives 1. Using COUNTROWS when you mean "orders" is one of the most common reasons order counts and average order value look wrong.
Average order value
Avg Order Value = DIVIDE ( [Total Sales], [Orders] )
Why distinct counts do not add up
Put Customers in a table by Sales[Region], the region where each sale happened. North shows 120, South 90, but the total shows 190, not 210. That is correct: 20 customers bought in both regions, and the total counts each customer once. Distinct counts are not additive. If someone asks for the total to equal the sum of the rows, they are asking a different question ("sum of regional customer counts"), which you can build like this:
Customers (sum of regions) =
SUMX ( VALUES ( Sales[Region] ), [Customers] )
More on this behaviour: Power BI total wrong? How to fix it.
Useful counting measures
1. Customers with no purchases in the selected period
Inactive Customers =
COUNTROWS (
FILTER ( Customer, ISBLANK ( [Total Sales] ) )
)
Iterates all customers and keeps those whose sales are blank in the current filter context (for example the selected month).
2. Repeat customers (more than one order)
Repeat Customers =
COUNTROWS (
FILTER ( VALUES ( Sales[CustomerID] ), [Orders] > 1 )
)
VALUES returns the customers who bought in the current context; the measure [Orders] is evaluated per customer thanks to context transition, explained in CALCULATE in DAX.
3. Repeat rate
Repeat Rate % = DIVIDE ( [Repeat Customers], [Customers] )
4. Orders above a value
Big Orders =
COUNTROWS (
FILTER ( VALUES ( Sales[OrderID] ), [Total Sales] > 50000 )
)
5. Missing data check
Lines without Customer = COUNTBLANK ( Sales[CustomerID] )
Add this to a hidden data-quality page. If it is not zero, some sales cannot be linked to a customer.
Performance notes
- DISTINCTCOUNT on a column with millions of unique values (such as a transaction ID) is heavier than COUNTROWS. If the table has one row per order, COUNTROWS gives the same answer faster.
- Count on the key column of the fact table rather than on a column from a related dimension when possible.
- Use Performance Analyzer to check slow visuals.
Common mistakes
- Counting order lines and calling them orders.
- Expecting distinct counts to add up across rows.
- Forgetting that DISTINCTCOUNT counts a blank as one extra value. Use DISTINCTCOUNTNOBLANK if blanks appear.
- Using a calculated column to flag repeat customers when a measure would respond to slicers correctly.
Practice task
Build a card row with Orders, Customers, Avg Order Value and Repeat Rate %. Add a Month slicer and check that the numbers change sensibly, then check that Customers in a Region table has a total smaller than or equal to the sum of the regions.
Related: Top N with RANKX and TOPN.
