Count(DISTINCT CustomerID)

Count, Count(DISTINCT) and counting key fields in Power BI

Count(DISTINCT Field) maps to DISTINCTCOUNT. Watch out for blanks, for which table you count from, and for the Qlik habit of counting key fields.

Direct equivalent DAX

Short answer: Count(DISTINCT CustomerID) becomes DISTINCTCOUNT(Sales[CustomerKey]) for customers with sales, or COUNTROWS(Customer) for customers in the filter. DISTINCTCOUNT counts BLANK as a value; DISTINCTCOUNTNOBLANK does not.

What it does in Qlik

Count(Field) counts non-null values over the records in the selection. Count(DISTINCT Field) counts the unique values. Qlik never counts null values. When the field is a key shared by two tables, it is ambiguous which table you are counting, and counting key fields is a well-known Qlik pitfall.

Qlik example

Qlik chart expressions
Count(DISTINCT CustomerID)   // unique customers
Count(OrderID)               // non-null OrderID values on the records
Count({<Year={2024}>} DISTINCT CustomerID)

Power BI equivalent

DAX measures

DAX
Customers with sales = DISTINCTCOUNT ( Sales[CustomerKey] )

Customers (dimension) = COUNTROWS ( Customer )

Order lines = COUNTROWS ( Sales )

Customers 2024 =
CALCULATE ( DISTINCTCOUNTNOBLANK ( Sales[CustomerKey] ), 'Date'[Year] = 2024 )

Gotchas and behaviour differences

  • DISTINCTCOUNT counts a BLANK as one extra value. Qlik's Count(DISTINCT ...) never counts null. Use DISTINCTCOUNTNOBLANK when blanks are possible.
  • COUNT(column) in DAX also skips blanks. COUNTROWS(table) counts every row, which is usually what Count(OrderID) meant.
  • Decide which table answers the question. A Product slicer filters Sales but not Customer (with single-direction relationships), so COUNTROWS(Customer) would ignore it.
  • Distinct counts are not additive. A matrix total is the distinct count over all rows, not the sum of the rows. Qlik behaves the same way.

Official documentation

Related pages

Spotted an error or a better pattern? QlikToDax is maintained by a working BI consultant; corrections are welcome via the About page. Last reviewed 2026-10-25.