Cardinality & Unique Counting: DISTINCTCOUNT & DISTINCTCOUNTNOBLANK
Overview & Learning Objectives
Measuring transaction volume (Total Orders, Total Deliveries, Total Logins) is one of the most common requirements in analytics. While beginners often write `COUNT(Orders[OrderID])`, enterprise DAX professionals always write `COUNTROWS(Orders)`. Understanding the architectural difference between table metadata inspection and column scanning makes your reports run up to 10x faster.
- Master the syntax and execution mechanics of `COUNTROWS(Table)`.
- Explain why `COUNTROWS()` is faster and more reliable than `COUNT(Column)`.
- Use `COUNTROWS()` inside filter statements like `CALCULATE([Sales], FILTER(..., COUNTROWS(...) > 0))`.
Industry Standard
Standard: Official DAX performance guidelines at Microsoft and Amazon declare `COUNTROWS(Table)` as the mandatory standard for row volume metrics, banning `COUNT(Table[ID])` on primary keys.
Real-World Example: Burger Point Quick Service Chain
Burger Point monitors daily order volume across 50 outlets. The orders table has 10 million rows.
| Measurement | DAX Formulation | Execution Engine Behavior | Performance Speed |
|---|---|---|---|
| Total Orders (Recommended) | COUNTROWS(Fact_Orders) | Inspects VertiPaq table metadata row count | Lightning Fast (< 2ms) |
| Total Orders (Unoptimized) | COUNT(Fact_Orders[OrderID]) | Scans & decompresses 10M column values | Slower (inspects every cell) |
Syntax & Core Workflow
Total Orders = COUNTROWS(Fact_Orders)
Parameters Breakdown
Table: The table or table expression to count (e.g. `Fact_Orders` or `FILTER(Fact_Orders, ...)`).Filter Context Awareness: `COUNTROWS` automatically obeys all active filters, slicers, and cross-table relationships.Blank Row Handling: Returns `BLANK()` if the table has zero rows in the current filter context.
Sample Walkthrough (Q&A)
Question: What happens if a primary key column has a blank row and you use `COUNT(Table[ID])`?
Formula / Action: COUNT will report 9,999 rows while the table actually contains 10,000 rows.
Result: Under-reports true business transactions.
Explanation: Because `COUNT()` ignores blank cells, any missing value in the specified column causes an undercount. `COUNTROWS(Table)` counts the actual physical row in the table, guaranteeing 100% accuracy.
Common Mistakes & Limitations
- Passing a column to COUNTROWS (e.g. `COUNTROWS(Fact_Orders[OrderID])`); COUNTROWS takes a Table, not a column.
- Using `COUNT(Table[Column])` on a primary key column out of habit from SQL (`SELECT COUNT(id)`).
Keyboard Shortcuts
| Action | Windows | Mac |
|---|---|---|
| Create Measure | Click Table -> New Measure | New Measure |
| Comment in DAX | // Text or /* Block */ | // Text |
Pro Tips & Modern Alternatives
- Combine `COUNTROWS` with `FILTER` to count rows meeting specific conditions: `COUNTROWS(FILTER(Fact_Orders, Fact_Orders[Status] = "Delivered"))`.
- Use `DISTINCTCOUNT` if you need unique customers rather than order transactions.