Customer retention by cohort in Power BI with DAX

How to build a cohort retention analysis in Power BI, customers grouped by the month of their first purchase, the share still buying in month 1, 2, 3 and later, a cohort triangle matrix with a heat map, retention curves, the DAX with a first-purchase column and a months-since axis, and how to read the result.

Short answer: a cohort is the group of customers who first bought (or signed up) in the same month. Retention in month n = customers of the cohort active in the n-th month after their first / the cohort's size. Shown as a triangle (cohorts down, months since first purchase across, a heat-map colour), it answers two questions a single churn number cannot: when in their life customers leave, and whether newer cohorts stay better than older ones.

A churn rate of 3% mixes customers in their first month with customers of five years. Cohorts separate them, so you can see whether last quarter's onboarding change actually kept people.

How does a cohort triangle look?

CohortSizeM0M1M2M3M4M5
Apr 2026410100%38%29%25%23%22%
May 2026380100%36%28%24%22%
Jun 2026450100%41%32%28%
Jul 2026500100%44%35%
Aug 2026520100%45%
Sep 2026480100%
Share of each cohort buying again, by months since first purchase

Read across a row for one cohort's life; read down a column to compare cohorts at the same age. Here month-1 retention rose from 36 to 45% from June: something changed for the better.

  • Apr
  • May
  • Jun
020406080100M0M1M2M3
Retention curves by cohort (%)

What is the DAX?

Add two calculated columns to Sales (or build them in Power Query), and a small axis table:

-- calculated columns on Sales
First Purchase Month =
VAR C = Sales[Customer ID]
RETURN EOMONTH ( CALCULATE ( MIN ( Sales[Date] ), ALL ( Sales ), Sales[Customer ID] = C ), -1 ) + 1

Months Since First =
( YEAR ( Sales[Date] ) - YEAR ( Sales[First Purchase Month] ) ) * 12
    + MONTH ( Sales[Date] ) - MONTH ( Sales[First Purchase Month] )

-- calculated table for the columns of the matrix
Cohort Age = GENERATESERIES ( 0, 24 )

Put Sales[First Purchase Month] on the matrix rows and 'Cohort Age'[Value] on its columns (no relationship), then:

Cohort Size =
CALCULATE ( DISTINCTCOUNT ( Sales[Customer ID] ), Sales[Months Since First] = 0 )

Active in Month n =
VAR N = SELECTEDVALUE ( 'Cohort Age'[Value] )
RETURN CALCULATE ( DISTINCTCOUNT ( Sales[Customer ID] ), Sales[Months Since First] = N )

Retention % = DIVIDE ( [Active in Month n], [Cohort Size] )

Apply a background colour scale to Retention % for the heat map (conditional formatting). Remove any Date slicer from the page, or filter only on First Purchase Month, because a date filter would cut off the later months of each cohort.

What does "active" mean?

  • Shops: bought at least once in that month (as above).
  • Subscriptions: still subscribed at the end of the month; use start and end dates instead of orders.
  • Apps: used the product in that month or week (see DAU/MAU).

Unbounded retention ("bought in month n or later") is smoother and suits products bought rarely.

What goes wrong?

  • Date slicers on the page. They cut cohorts short; filter by cohort month only.
  • Incomplete months. The newest cohort's last column is a partial month; hide ages that have not fully passed.
  • Tiny cohorts. 30 customers swing by 3 points per customer; show the size column.
  • Calculated columns on huge tables. For millions of rows, compute first purchase month in Power Query or the source.

Where can you check this?

Where do you start?

Build the triangle for the last twelve monthly cohorts and compare month-1 retention down the column. Customer lifetime value turns retention into money.

Keep reading

More from the blog.

Every post

Next

Building this? Say hello.

A question about this post, a pattern you would build differently, or the next thing you want written out: Behnia reads every message.