Skip to content

Customer Cohort Analysis – Grouping of Customers into Monthly Cohorts based on their purchase dates

>> Download the sample (Power BI)

This sample:

  • Groups each customer into a “Join Month Cohort”, based on the month in which they made their first purchase

  • For each “Join Month Cohort”, groups the customers in that cohort into a monthly retention period group, based on how long that customer’s retention period is, or was.

  • A customer’s retention period is the number of days between the customer’s onboarding date and their next (second) purchase.

Cohort Customers =
COUNTROWS ( Customer_Table )
Cohort Month =
VAR JoinDate = [Join Date]
RETURN
CALCULATE (
SELECTEDVALUE ( Calendar_Table[Month & Year] ),
FILTER ( ALL ( Calendar_Table ), Calendar_Table[Date] = JoinDate )
)
// works in customer context
Cohort Start Month =
VAR OnboardingDate = [Onboarding Date]
RETURN
CALCULATE (
SELECTEDVALUE ( Calendar_Table[Month & Year] ),
FILTER ( ALL ( Calendar_Table ), Calendar_Table[Date] = [Onboarding Date] )
)
Join Date =
MIN ( Sales_Table[Date] )
// works in Customer Context

No. of Unique Customers as a % of all Customers

Section titled “No. of Unique Customers as a % of all Customers”
No. of Unique Customers as a % of all Customers =
CALCULATE (
DIVIDE ( [No. of Unique Customers in Retention Period], [Unique Customers], 0 ),
TREATAS (
VALUES ( Calendar_Table[Month & Year] ),
Customer_Table[Join Month Cohort]
)
)

No. of Unique Customers in Retention Period

Section titled “No. of Unique Customers in Retention Period”
No. of Unique Customers in Retention Period =
VAR CustomerDimension =
VALUES ( Customer_Table[Customer] )
RETURN
IF (
SELECTEDVALUE ( 'Retention Period Monthly Cohorts'[Period] ) = 0,
[Unique Customers],
CALCULATE (
CALCULATE (
[Unique Customers],
FILTER (
CustomerDimension,
COUNTROWS (
FILTER (
'Retention Period Monthly Cohorts',
[Retention Days] > 'Retention Period Monthly Cohorts'[Min Days]
&& [Retention Days] <= 'Retention Period Monthly Cohorts'[Max Days]
)
) > 0
)
),
TREATAS (
VALUES ( Calendar_Table[Month & Year] ),
Customer_Table[Join Month Cohort]
)
)
)
Onboarding Date =
CALCULATE (
[Join Date],
ALL ( Sales_Table ),
VALUES ( Customer_Table[Customer] )
)
Retention Days =
VALUE ( [Second Purchase Date] ) - VALUE ( [Onboarding Date] )
Second Purchase Date =
CALCULATE (
MIN ( Sales_Table[Date] ),
FILTER ( ALL ( Sales_Table ), Sales_Table[Date] > [Onboarding Date] ),
VALUES ( Customer_Table[Customer] )
)
//looking for the min sale AFTER the initial first sale
Unique Customers =
COUNTROWS ( VALUES ( Sales_Table[Customer] ) )
Calendar_Table =
GENERATE (
CALENDAR ( DATE ( 2017, 1, 1 ), DATE ( 2019, 12, 31 ) ),
VAR currentDay = [Date]
VAR Day =
DAY ( currentDay )
VAR Month =
MONTH ( currentDay )
VAR Year =
YEAR ( currentDay )
RETURN
ROW ( "Day", day, "Month", month, "Year", year )
)
Join Date =
[Join Date]
Join Month Cohort =
[Cohort Month]
Join Month Index =
CALCULATE (
SELECTEDVALUE ( Calendar_Table[YearMonthInt] ) * 100,
FILTER (
Calendar_Table,
Calendar_Table[Month & Year] = 'Cohort Measures'[Cohort Start Month]
)
)