COUNT and DISTINCTCOUNT in Power BI - Real Business Scenario
| TransactionID | CustomerID | SaleDate | Amount |
|---|---|---|---|
| 1001 | C001 | 2024-01-05 | 150 |
| 1002 | C002 | 2024-01-15 | 200 |
| 1003 | C001 | 2024-01-20 | 100 |
| 1004 | C003 | 2024-02-02 | 250 |
| 1005 | C004 | 2024-02-10 | 300 |
| 1006 | C002 | 2024-02-15 | 180 |
| 1007 | C005 | 2024-03-01 | 220 |
| 1008 | C001 | 2024-03-05 | 130 |
| 1009 | C006 | 2024-03-10 | 170 |
| 1010 | C005 | 2024-03-15 | 210 |
MonthYear = FORMAT(Sales[SaleDate], "YYYY-MM")Total Transactions = COUNT(Sales[TransactionID])Unique Customers = DISTINCTCOUNT(Sales[CustomerID])Table visual configuration: Rows = MonthYear, Values = Total Transactions, Unique CustomersMonthYear | Total Transactions | Unique Customers --------------------------------------------- 2024-01 | 3 | 2 2024-02 | 3 | 3 2024-03 | 4 | 3
Create a line chart showing the trend of unique customers over the months.
Practice
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
