Stop 07 · DAX FundamentalsTopics · 6/10

COUNT, COUNTROWS and DISTINCTCOUNT

Part of the Power BI Roadmap

In short

"How many orders?" and "how many customers?" sound similar but need different functions. Picking the right count is one of the most common Power BI interview questions.

COUNTROWS counts the rows of a table, COUNT counts non-blank values in a column, and DISTINCTCOUNT counts unique values, such as unique customers or unique orders.

The jaadu, as a cinema usher, sorts a heap of ticket stubs into one tall pile and several small family bundles tied with string.

Think of it like this

Counting at a cinema

Count the ticket stubs and you get tickets sold (COUNTROWS). Count stubs that have a seat number written on them and you skip the blank ones (COUNT). Count different phone numbers on the bookings and you get unique customers, because one family booked five tickets (DISTINCTCOUNT).

Watch it happen

Six sales rows, CustomerKey column

C1
0
C2
1
C1
2
blank
3
C3
4
C1
5

1/5Six rows in Sales. One has no customer recorded.

The big ideas

What you need to know

COUNTROWS counts a table

COUNTROWS ( Sales ) is the clearest way to count rows. It takes a table, not a column.

COUNT counts non-blanks

COUNT ( Sales[Discount] ) counts rows where Discount isn't blank. Useful for 'how many had a discount'.

DISTINCTCOUNT counts unique

Unique customers, unique bills, unique products sold.

Blank counts as a value

DISTINCTCOUNT includes blank as one value. DISTINCTCOUNTNOBLANK leaves it out.

See it in code

Walk through the code

dax
1Sales Lines = COUNTROWS ( Sales )2 3Bills = DISTINCTCOUNT ( Sales[BillNo] )4 5Customers = DISTINCTCOUNTNOBLANK ( Sales[CustomerKey] )6 7Lines With Discount = COUNT ( Sales[Discount] )8 9Bills per Customer = DIVIDE ( [Bills], [Customers] )

1/5Every product line on every bill.

Five counting measures that answer different questions about the same table.

Save yourself the pain

Common mistakes

Oops

Using COUNTROWS ( Sales ) to report number of orders when Sales has one row per item.

Do this instead

Use DISTINCTCOUNT on the order or bill number column.

Oops

Summing a Customers measure across months to get yearly customers.

Do this instead

A customer who bought in three months is counted three times. Evaluate DISTINCTCOUNT at year level instead.

Your mission

Count four ways

~15 min

Quick check

Which measure tells you how many different customers bought something?

Go deeper

  1. 1Create Order Lines with COUNTROWS ( Sales ).
  2. 2Create Unique Customers with DISTINCTCOUNT ( Sales[CustomerID] ).
  3. 3Explain why the two numbers differ in the same visual.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge