Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more.
Get startedGrow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.
Hi community,
I am working on a measure that is able to calculate a dynamic customer churn, so I can visualize the trend of lost customers over time. The way a lost customer is defined is if they purchased any unit in the month n- 1 and not in month n.
I have made the two below measures and they work fine for the current month but it doesn't work as intended looking back as, I believe that the MAX function, ensures that if all customers that made a unit purchase in Month X will not be counted as lost for all the month in the past. How do I modify the below so I can create a dynamic customer churn trend?
Thank you in advance
Solved! Go to Solution.
try this:
# Lost customers 1m =
-- date start selected month
VAR dssm = CALCULATE(STARTOFMONTH(Dim_Calendar[Date key]), Dim_Calendar[Date key]= MAX(Dim_Calendar[Date key]))
-- date end selected month
VAR desm= ENDOFMONTH(Dim_Calendar[Date key])
-- dates selected month
VAR dsm = DATESBETWEEN(Dim_Calendar[Date key], dssm, desm)
-- dates previous month
VAR dpm = PREVIOUSMONTH(dsm)
-- customers selected month
VAR csm = CALCULATETABLE(VALUES(Financials[Account key])
, ALL( Dim_Calendar), dsm
, Financials[Line item] = "Units")
-- customers previous month
VAR cpm = CALCULATETABLE(VALUES(Financials[Account key])
, ALL( Dim_Calendar), dpm
, Financials[Line item] = "Units")
-- count the customers in the previos month that are not in the selected month
RETURN COUNTROWS(EXCEPT(cpm,csm))
try this:
# Lost customers 1m =
-- date start selected month
VAR dssm = CALCULATE(STARTOFMONTH(Dim_Calendar[Date key]), Dim_Calendar[Date key]= MAX(Dim_Calendar[Date key]))
-- date end selected month
VAR desm= ENDOFMONTH(Dim_Calendar[Date key])
-- dates selected month
VAR dsm = DATESBETWEEN(Dim_Calendar[Date key], dssm, desm)
-- dates previous month
VAR dpm = PREVIOUSMONTH(dsm)
-- customers selected month
VAR csm = CALCULATETABLE(VALUES(Financials[Account key])
, ALL( Dim_Calendar), dsm
, Financials[Line item] = "Units")
-- customers previous month
VAR cpm = CALCULATETABLE(VALUES(Financials[Account key])
, ALL( Dim_Calendar), dpm
, Financials[Line item] = "Units")
-- count the customers in the previos month that are not in the selected month
RETURN COUNTROWS(EXCEPT(cpm,csm))
This one worked very well. Thank you.
Last Purchase Date =
CALCULATE(
MAX(Financials[Date Key]),
ALLEXCEPT(Financials, Financials[Account key]),
Financials[Line item] = "Units"
)
# Lost Customers 1m =
VAR CurrentDate = MAX(Dim_Calendar[Date key])
VAR LastPurchaseDates =
CALCULATETABLE(
SUMMARIZE(
Financials,
Financials[Account key],
"Last Purchase Date", [Last Purchase Date]
),
Financials[Date Key] <= CurrentDate
)
VAR LostCustomers =
COUNTROWS(
FILTER(
LastPurchaseDates,
[Last Purchase Date] < CurrentDate &&
[Last Purchase Date] >= EOMONTH(CurrentDate, -1)
)
)
RETURN
LostCustomers
In this approach:
Make sure to adjust the measures based on your data model and requirements. This approach should help you create a dynamic churn trend based on the criteria you've defined.
Hi,
Thank you very much for your reply. I tried your approach and it has the same issue as my original measure as it won't work on a trend line as a customer cannot be considered lost if I made a purchase in the current period. A customer can be considered lost multiple month if you look at it month by month.
Ah, I see what you're aiming for now. You want to track customers who were active in the previous month but are not active in the current month. This means you want to identify churned customers on a month-by-month basis.
To create a dynamic measure that captures customer churn on a monthly basis, you can use the following approach:
Here's how you can modify your DAX measures to capture this:
Active Customers Current Month =
CALCULATETABLE(
VALUES(Financials[Account key]),
Financials[Line item] = "Units",
Financials[Date Key] <= MAX(Dim_Calendar[Date Key])
)
Active Customers Previous Month =
CALCULATETABLE(
VALUES(Financials[Account key]),
Financials[Line item] = "Units",
Financials[Date Key] <= EOMONTH(MAX(Dim_Calendar[Date Key]), -1) &&
Financials[Date Key] > EOMONTH(MAX(Dim_Calendar[Date Key]), -2)
)
Churned Customers =
VAR ActiveInPreviousMonth = COUNTROWS(Active Customers Previous Month)
VAR ActiveInCurrentMonth = COUNTROWS(Active Customers Current Month)
VAR Churned = ActiveInPreviousMonth - ActiveInCurrentMonth
RETURN
IF(Churned > 0, Churned, 0)
In this approach:
This method will allow you to capture the monthly churn of customers dynamically, considering only those who were active in the previous month but not in the current month.
Thanks again for the help. I did try this approach but there seems to be an error in Measure 2, as it doesn't work in the row context and only with the total.
You're correct. The context transition from row context to filter context can sometimes lead to unexpected results. Let's revise the approach to ensure that the measure works correctly in both row and filter contexts.
Instead of creating a separate measure for identifying customers who did not purchase in the current month, let's incorporate that logic directly into the measure that calculates the lost customers dynamically.
Here's how you can modify the approach:
Customers_LastMonth =
VAR LastMonthEndDate = EOMONTH(TODAY(), -2) -- Change TODAY() if needed
RETURN
CALCULATETABLE(
VALUES(Financials[Account key]),
Financials[Date Key] >= EOMONTH(LastMonthEndDate, -1) && Financials[Date Key] < LastMonthEndDate
)
# Lost Customers 1m =
VAR LastMonthCustomers = Customers_LastMonth
VAR AllMonths = VALUES(Financials[Date Key])
VAR LostCustomersCount =
SUMX(
AllMonths,
VAR ThisMonthEndDate = [Date Key]
VAR ThisMonthCustomers =
CALCULATETABLE(
VALUES(Financials[Account key]),
Financials[Date Key] >= EOMONTH(ThisMonthEndDate, -1) && Financials[Date Key] < ThisMonthEndDate
)
VAR LostCustomers =
CALCULATE(
COUNTROWS(
EXCEPT(
LastMonthCustomers,
ThisMonthCustomers
)
)
)
RETURN
LostCustomers
)
RETURN
LostCustomersCount
In this revised approach, we keep the logic within the single measure # Lost Customers 1m. By using SUMX and iterating over each month, we calculate the count of lost customers dynamically.
This should help ensure that the measure works correctly in both row and filter contexts, providing you with a dynamic count of lost customers for each month.
User | Count |
---|---|
51 | |
46 | |
20 | |
16 | |
14 |
User | Count |
---|---|
108 | |
54 | |
31 | |
20 | |
18 |