COUNT and DISTINCTCOUNT in Power BI - Deep Dive
Data Column: [A, B, A, C, B] COUNT: 5 (counts all) DISTINCTCOUNT: 3 (counts A, B, C only once each)
βββββββββββββββ βββββββββββββββββ
β Data ββββββββΆβ COUNT β
β [A, B, A] β β Counts all β
βββββββββββββββ β non-blank β
βββββββββββββββββ
β
βΌ
Result: 3
βββββββββββββββ βββββββββββββββββ
β Data ββββββββΆβ DISTINCTCOUNT β
β [A, B, A] β β Builds unique β
βββββββββββββββ β set and countsβ
βββββββββββββββββ
β
βΌ
Result: 2Practice
What does the DISTINCTCOUNT function do in Power BI?
Solution
Step 1: Understand DISTINCTCOUNT purpose
DISTINCTCOUNT counts unique non-empty values in a column, ignoring duplicates and blanks.Step 2: Compare with other options
Other options describe counting all values, empty values, or rows, which are incorrect for DISTINCTCOUNT.Final Answer:
Counts the number of unique non-empty values in a column -> Option DQuick Check:
DISTINCTCOUNT = unique non-empty count [OK]
- Confusing DISTINCTCOUNT with COUNT
- Thinking it counts empty or blank values
- Assuming it counts total rows
Which of the following is the correct syntax to count all non-empty values in the Sales[OrderID] column?
?Solution
Step 1: Identify COUNT syntax
COUNT(column) counts all non-empty values in the specified column.Step 2: Eliminate incorrect options
DISTINCTCOUNT counts unique values, COUNTROWS requires a table, COUNTBLANK counts blanks, so only COUNT is correct here.Final Answer:
COUNT(Sales[OrderID]) -> Option BQuick Check:
COUNT(column) counts non-empty values [OK]
- Using COUNTROWS on a column instead of a table
- Confusing DISTINCTCOUNT with COUNT
- Using COUNTBLANK instead of COUNT
Given the table Products with the Category column containing values: {"Fruit", "Fruit", "Vegetable", "Fruit", "Vegetable", "Grain"}, what is the result of DISTINCTCOUNT(Products[Category])?
Solution
Step 1: Identify unique categories
The unique values in Category are "Fruit", "Vegetable", and "Grain" which totals 3.Step 2: Apply DISTINCTCOUNT
DISTINCTCOUNT counts these unique non-empty values, so the result is 3.Final Answer:
3 -> Option AQuick Check:
DISTINCTCOUNT = 3 unique categories [OK]
- Counting total rows instead of unique values
- Confusing DISTINCTCOUNT with COUNT
- Including duplicates in count
Consider this DAX measure:UniqueCustomers = COUNT(Customer[CustomerID])
Why might this measure give an incorrect count of unique customers?
Solution
Step 1: Understand COUNT behavior
COUNT counts all non-empty values, including duplicates, so it does not count unique customers.Step 2: Identify correct function for unique count
To count unique customers, DISTINCTCOUNT should be used instead of COUNT.Final Answer:
Because COUNT counts all non-empty values, including duplicates -> Option CQuick Check:
COUNT counts duplicates, use DISTINCTCOUNT for unique [OK]
- Assuming COUNT counts unique values
- Thinking COUNT counts blanks
- Believing CustomerID must be numeric for COUNT
You have a sales table with 1000 rows. The CustomerID column has 900 non-empty values, but only 850 unique customers. Which DAX measure correctly returns the number of unique customers who made a purchase?
Solution
Step 1: Understand the data counts
There are 900 non-empty CustomerID values but only 850 unique customers.Step 2: Choose measure for unique count
DISTINCTCOUNT returns the count of unique non-empty values, which is 850, the correct unique customer count.Final Answer:
DISTINCTCOUNT(Sales[CustomerID]) -> Option AQuick Check:
Use DISTINCTCOUNT for unique customer count [OK]
- Using COUNT which counts duplicates
- Using COUNTROWS which counts all rows
- Using COUNTBLANK which counts blanks
Ready to prove it?
Pass the test and this pattern moves unknown
