Prompt
Answer
Customer Monthly Movement Calculation in DAX
Description
To calculate the movement of customers based on volumes on a month-by-month basis, a DAX formula can be crafted to track whether a customer is new, retained, or lost in a given month compared to the previous month.
Formula Explanation
The following DAX formulas calculate the customer movement:
Calculate Total Volume: First, compute the total volume for each customer.
Identify Returning Customers: Determine whether the customer has volumes in both the current and the previous month.
Identify New Customers: Identify customers who have volumes in the current month but none in the previous month.
Identify Lost Customers: Identify customers who had volumes in the previous month but none in the current month.
DAX Formulas
Calculate Total Volume
TotalVolume = SUM(Sales[Volume])
Identify Returning Customers
ReturningCustomers =
VAR CurrentMonth = MAX(Sales[Date])
VAR PreviousMonth = EDATE(CurrentMonth, -1)
RETURN
CALCULATETABLE(
VALUES(Sales[CustomerID]),
FILTER(Sales, Sales[Date] = CurrentMonth),
INTERSECT(
VALUES(Sales[CustomerID]),
CALCULATETABLE(
VALUES(Sales[CustomerID]),
FILTER(Sales, Sales[Date] = PreviousMonth)
)
)
)
Identify New Customers
NewCustomers =
VAR CurrentMonth = MAX(Sales[Date])
VAR PreviousMonth = EDATE(CurrentMonth, -1)
RETURN
CALCULATETABLE(
VALUES(Sales[CustomerID]),
FILTER(Sales, Sales[Date] = CurrentMonth),
EXCEPT(
VALUES(Sales[CustomerID]),
CALCULATETABLE(
VALUES(Sales[CustomerID]),
FILTER(Sales, Sales[Date] = PreviousMonth)
)
)
)
Identify Lost Customers
LostCustomers =
VAR CurrentMonth = MAX(Sales[Date])
VAR PreviousMonth = EDATE(CurrentMonth, -1)
RETURN
CALCULATETABLE(
VALUES(Sales[CustomerID]),
FILTER(Sales, Sales[Date] = PreviousMonth),
EXCEPT(
VALUES(Sales[CustomerID]),
CALCULATETABLE(
VALUES(Sales[CustomerID]),
FILTER(Sales, Sales[Date] = CurrentMonth)
)
)
)
Practical Example
Consider a dataset with the following sales records:
Date | CustomerID | Volume |
---|---|---|
2023-01-01 | C001 | 100 |
2023-01-15 | C002 | 200 |
2023-02-01 | C001 | 150 |
2023-02-14 | C003 | 300 |
2023-03-01 | C002 | 250 |
2023-03-15 | C004 | 350 |
Applying the above formulas would yield:
- Returning Customers in February: C001
- New Customers in February: C003
- Lost Customers in February: C002
This approach allows for a dynamic calculation of customer movements based on volumes, providing insights into the retention, acquisition, and churn of customers over time.
For further learning and mastery of DAX, consider exploring comprehensive courses available on the Enterprise DNA Platform.
Description
This guide explains how to use DAX to analyze customer movements monthly, classifying customers as new, returning, or lost based on sales volumes. It includes detailed formulas and a practical example for clarity.