Photo by Tamarcus Brown on Unsplash
How to Calculate New Customers Enrollments Using Power BI DAX Calculated Columns + Measure
Table of contents
- Overview of the Data Model
- Step 1: Calculating the First Purchase Date for Each Customer
- DAX Code to Calculate First Purchase Date:
- Explanation:
- Step 2: Flagging First Transactions in the Sales Table
- DAX Code to Flag First Transactions:
- Explanation:
- Step 3: Calculating the Number of New Customers
- DAX Code to Calculate New Customers:
- Explanation:
- Note:
- Final Visualization
- Conclusion
In this article, we will walk through a practical example of using DAX in Power BI to calculate New Customers. Identifying when a customer makes their first purchase is crucial for businesses that want to analyze customer acquisition and growth over time.
This tutorial will guide you through the process using DAX-calculated columns and measures with examples and screenshots to make it easy to follow.
Overview of the Data Model
Our Power BI data model consists of three key tables:
Sales – contains transactional data.
Customers – includes customer-related information.
Calendar – a date table used to slice the data by time.
Step 1: Calculating the First Purchase Date for Each Customer
The first step in identifying new customers is determining when each customer made their first purchase. To do this, we need to create a calculated column in the Customers table that tracks the First Purchase Date for each customer.
DAX Code to Calculate First Purchase Date:
FirstPurchaseDate = CALCULATE(MIN(Sales[OrderDate]))
Explanation:
MIN(Sales[OrderDate]): This returns the earliest
OrderDate
for each customer.CALCULATE: Adjusts the context to evaluate the minimum order date for each customer.
Because there is already a relationship between the Sales and Customers tables, the calculation automatically determines the first transaction date per customer based on the CustomerKey
.
Step 2: Flagging First Transactions in the Sales Table
Once we have the first purchase date, the next step is to flag transactions that represent the customer’s first purchase. This helps us distinguish between initial and repeat transactions in the Sales table.
DAX Code to Flag First Transactions:
Flag_FirstTransaction = RELATED(Customers[FirstPurchaseDate]) = Sales[OrderDate]
Explanation:
RELATED: This function brings the
FirstPurchaseDate
from the Customers table into the context of the Sales table.This comparison checks whether the
OrderDate
in the Sales table matches theFirstPurchaseDate
for the customer. If it does, the column returnsTrue
, marking that transaction as the customer’s first.
Step 3: Calculating the Number of New Customers
Now that we have flagged the first transactions, we can calculate the total number of New Customers for any time period using a DAX measure. This measure will count unique customer keys where the first transaction flag is True
.
DAX Code to Calculate New Customers:
New_Customers = CALCULATE(
DISTINCTCOUNT(Sales[CustomerKey]),
Sales[Flag_FirstTransaction]
)
Explanation:
DISTINCTCOUNT(Sales[CustomerKey]): Counts the unique customer keys.
CALCULATE: Recalculates the distinct count, but only includes rows where
Flag_FirstTransaction
isTrue
, which effectively counts only the new customers.
Note:
Since there is an existing relationship between Calendar[Date]
and Sales[OrderDate]
, you don’t need to define another relationship for the calculation. This ensures that the measure works with the Calendar
table for time-based analysis.
Final Visualization
You can now use this DAX measure in your Power BI report to create visualizations, such as a bar chart or line graph, to track the number of New Customers over time. By linking the measure to your Calendar
table, you can easily filter or slice the data by specific time periods to gain more insights.
Conclusion
Using DAX in Power BI for calculating New Customers is a practical way to track business growth and customer acquisition trends. By following this approach, you can gain actionable insights into your customer base and make more informed decisions about your marketing and sales strategies.
The three steps we’ve covered — calculating the first purchase date, flagging first transactions, and counting new customers — are fundamental techniques in Power BI that can be extended to many other business metrics.