To implement this recipe, do the following:
- Create the following measures:
Lost Customers =
VAR __Threshold = 1
VAR __ThresholdUnit = "YEARS"
VAR __Month = MAX('R03_Dates'[Month])
VAR __Year = MAX('R03_Dates'[Year])
VAR __MonthStart = DATE(__Year, __Month, 1)
VAR __MonthEnd = MAX('R03_Dates'[Date])
VAR __PreviousCustomers =
SUMMARIZE(
FILTER(
'R03_Table',
[Date] < __MonthEnd
),
[Customer],
"__LastPurchase",MAX([Date])
)
VAR __PreviousCustomers1 =
ADDCOLUMNS(
__PreviousCustomers,
"__LostDate",
SWITCH(
__ThresholdUnit,
"DAYS",[__LastPurchase] + __Threshold,
"MONTHS",EOMONTH([__LastPurchase],__Threshold),
"YEARS",DATE(YEAR([__LastPurchase]) + __Threshold,MONTH([__LastPurchase]),1)
)
)
VAR __LostCustomers =
DISTINCT(
SELECTCOLUMNS(
FILTER(
__PreviousCustomers1,
MONTH([__LostDate]) = __Month &&
YEAR([__LostDate]) = __Year),
"__Customer",[Customer]
)
)
RETURN
COUNTROWS(__LostCustomers)
- Create the Recovered Customers measure using the code in the R03_RecoveredCustomers.txt text file located in the GitHub repository.
- On a Report page, create a matrix visualization and place the Month Name column from R03_Dates into the Rows area, the Year column from R03_Dates into the Columns area, and the Lost Customers measure into the Values area.
- On a report page, create a matrix visualization and place the Month Name column from R03_Dates into the Rows area, the Year column from R03_Dates into the Columns area, and the Recovered Customers measure into the Values area.