How many total sales transactions are there, and how many unique customers made purchases?
COUNT and DISTINCTCOUNT in Power BI - Dashboard Guide
| TransactionID | CustomerID | Product | Amount |
|---|---|---|---|
| 1001 | C001 | Notebook | 15 |
| 1002 | C002 | Pen | 5 |
| 1003 | C001 | Backpack | 45 |
| 1004 | C003 | Pen | 5 |
| 1005 | C004 | Notebook | 15 |
| 1006 | C002 | Backpack | 45 |
| 1007 | C005 | Pen | 5 |
KPI Card: Total Transactions
Shows the total number of sales transactions.
DAX formula: Total Transactions = COUNT(Sales[TransactionID])
Result: 7
KPI Card: Unique Customers
Shows the number of distinct customers who made purchases.
DAX formula: Unique Customers = DISTINCTCOUNT(Sales[CustomerID])
Result: 5
Table: Sales Details
Displays all sales transactions with details.
+----------------------+---------------------+
| Total Transactions | Unique Customers |
| [ 7 ] | [ 5 ] |
+----------------------+---------------------+
| |
| Sales Details Table |
| |
+------------------------------------------+
Adding a slicer to filter by Product will update both KPI cards and the sales details table to show data only for the selected product(s).
For example, selecting "Pen" will update:
- Total Transactions to 3 (transactions 1002, 1004, 1007)
- Unique Customers to 3 (customers C002, C003, C005)
- Sales Details Table to show only those 3 transactions
If you add a filter for CustomerID = C001, which components update and what are their new values?
- Total Transactions updates to 2 (transactions 1001, 1003)
- Unique Customers updates to 1 (customer C001)
- Sales Details Table shows only transactions 1001 and 1003
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
