A stable customer key
Every order must carry the same ID for the same buyer. Guest checkouts that mint a new ID per order make every return visit look like a brand-new customer, and the matrix quietly shows zero retention.
Power BI How-To / Retention Patterns
A Power BI cohort analysis groups customers by the month of their first order, then shows how many come back in each month after it, laid out as a retention heatmap. This guide builds the generic version from a plain orders table: three calculated columns, three DAX measures, a worked retention table and a fix-it checklist. If you need subscription MRR cohorts with expansion and contraction, that is a different model, covered by our SaaS ARR and churn dashboard.
The short version
Every order must carry the same ID for the same buyer. Guest checkouts that mint a new ID per order make every return visit look like a brand-new customer, and the matrix quietly shows zero retention.
The first order date, truncated to the first of its month, is the row label. It is a calculated column, so it never shifts when someone filters the report.
DATEDIFF from the cohort month to each order date gives 0, 1, 2… That integer is the column header, which is what lets cohorts of different calendar months line up by age.
Retention is active customers divided by the cohort’s starting headcount. Pin that headcount to month zero and every cell in a row divides by the same number.
A cohort analysis groups customers by the month they first bought, then tracks what share of each group comes back in every later month. Reading across a row shows how one cohort decays; reading down a column compares cohorts at the same age, which tells you whether retention is improving or getting worse over time.
A single repeat-purchase rate hides that second view. If last spring’s customers came back at a higher rate than this spring’s, an all-time average blends the two and you never see the slide. The cohort layout separates acquisition from retention: a big month of new customers inflates revenue, but it cannot make an older cohort look better than it is. That is why cohort retention is a standard deliverable on ecommerce and subscription dashboards, and why it is worth building once, correctly, rather than rebuilding in a spreadsheet each quarter.
You need three things: an orders table with a customer ID, an order date and an amount; a customers table with one row per customer, related one-to-many to orders; and, for any calendar slicing, a marked Date table. Nothing else is required, which is why the same pattern works for Shopify, Stripe, QuickBooks or a SQL order history.
The customer key matters more than anything else on this page. If your store exports guest orders with a fresh ID each time, deduplicate on a normalized email address upstream (in Power Query or the source) before building cohorts. Keep the relationship single-direction, from customers to orders. If you also want to slice by order calendar, relate the Date table to the order date and mark it; our guide to time intelligence DAX and Date tables covers the date mechanics this model leans on.
Add a First Order Date column on the customers table with CALCULATE( MIN( Orders[OrderDate] ) ), truncate it to the first of the month to get the cohort, then add a Months Since First Order column on orders using DATEDIFF. Those two columns become the rows and columns of the cohort matrix.
The three calculated columns are:
First Order Date = CALCULATE( MIN( Orders[OrderDate] ) )Cohort Month = DATE( YEAR( Customers[First Order Date] ), MONTH( Customers[First Order Date] ), 1 )Months Since First Order = DATEDIFF( RELATED( Customers[Cohort Month] ), Orders[OrderDate], MONTH )In the first column, CALCULATE turns the current customer row into a filter (context transition), so MIN only sees that customer’s orders. Calculated columns are computed at refresh and ignore report slicers, which is exactly what you want: a customer’s cohort should not move because someone filtered the page to one region. DATEDIFF with the MONTH interval counts calendar-month boundaries crossed, so an order on the last day of the cohort month is month 0 and an order the next day is month 1. Microsoft’s DATEDIFF function reference (opens in new tab) documents the interval options.
Three measures do the work. Active Customers is a distinct count of customer IDs on the orders table. Cohort Size is the same count forced to month zero, so every cell divides by the cohort’s starting headcount. Retention % divides the first by the second with DIVIDE, which returns blank instead of an error.
| Measure | DAX | What it returns in a cell |
|---|---|---|
| Active Customers | DISTINCTCOUNT( Orders[CustomerID] ) |
Customers from that cohort who placed at least one order in that month index |
| Cohort Size | CALCULATE( [Active Customers], Orders[Months Since First Order] = 0 ) |
The cohort’s starting headcount, repeated across the whole row |
| Retention % | DIVIDE( [Active Customers], [Cohort Size] ) |
The share of the cohort active in that month; always 100% in month 0 |
The Cohort Size trick works because every customer, by definition, ordered in month 0. The filter argument replaces the column header’s month index with 0 while the row’s cohort filter stays in place, so month 3 of the oldest cohort divides by the same headcount as month 1. If you would rather not rely on that, COUNTROWS( Customers ) returns the same number here, because the single-direction relationship means the months-since filter on orders never reaches the customers table.
Below is an illustrative three-cohort example on sample data. Each row is a first-order month, each column is months since that first order, and each cell is the share of the cohort that ordered in that month. Empty cells are not zero; those cohorts simply have not reached that age yet.
| Cohort | Cohort Size | Month 0 | Month 1 | Month 2 | Month 3 |
|---|---|---|---|---|---|
| Cohort A | 200 | 100% (200) | 30% (60) | 24% (48) | 21% (42) |
| Cohort B | 150 | 100% (150) | 28% (42) | 22% (33) | Not yet reached |
| Cohort C | 120 | 100% (120) | 35% (42) | Not yet reached | Not yet reached |
Read it both ways. Across Cohort A, the biggest drop is between month 0 and month 1, and the curve flattens after that: the customers still buying in month 2 mostly keep buying. Down the Month 1 column, Cohort C returned at 35% against 30% and 28% for the older cohorts, which is the signal worth investigating. Something changed for that cohort (an offer, a product, a follow-up email), and the matrix tells you where to look, not why. Note also that 42 active customers means 21% of Cohort A but 35% of Cohort C; raw counts mislead whenever cohort sizes differ, which is why the heatmap colors the percentage.
Use the built-in matrix visual: Cohort Month on rows, Months Since First Order on columns and Retention % as the value. Then apply a background color scale through conditional formatting so strong retention reads dark and weak retention reads light. Turn off row and column totals, because they mix cohorts of different ages.
Three finishing touches make it readable. Give Cohort Month a mmm yyyy format string so rows show as month labels rather than full dates. Keep month 0 out of the color scale, either by filtering it off the visual or by setting a fixed maximum below 100% in the scale settings; otherwise the always-100% first column takes the darkest color and flattens the contrast everywhere else; Cohort Size can live in a tooltip or a separate card. And format Retention % as a percentage with no decimals, which is enough precision to compare cohorts. Microsoft’s guide to conditional table formatting in Power BI (opens in new tab) walks through the color-scale settings. For a second view, a line chart with Months Since First Order on the x-axis and Cohort Month as the legend draws each cohort’s retention curve; keep it to the latest handful of cohorts so the lines stay legible.
Most broken cohort reports come from four causes: customer IDs that are not stable across orders, a date slicer that removes month-zero orders from Cohort Size, refunds or zero-value orders counted as returns, and a current partial month that makes the newest cohorts look weaker than they are. Check those before rewriting any DAX.
Customers[Cohort Month] instead, or add REMOVEFILTERS( 'Date' ) to Cohort Size.Customer-count retention answers whether people come back. Revenue retention answers whether their spend comes back, and subscription businesses usually need MRR cohorts that track expansion, contraction and churn per month. Both reuse the cohort column from this guide, but they swap the distinct count for a sales measure or a monthly MRR snapshot table.
Revenue retention is a two-line change: Revenue Retention % = DIVIDE( [Total Sales], CALCULATE( [Total Sales], Orders[Months Since First Order] = 0 ) ). Unlike customer retention it can climb above 100% when returning buyers spend more than they did at first. For a store, the same model runs straight off order exports, which is how we build the repeat-customer views in a Shopify Power BI dashboard. Recurring revenue is different: an MRR cohort needs one row per customer per month with the contracted amount, so a quiet month on a paid annual plan is not mistaken for churn. That model, with net revenue retention and an MRR movement bridge, is part of the SaaS ARR and churn dashboard we build from billing data.
Bring in help when the cohort numbers will drive spend decisions and the order data is messy: several stores or billing systems, guest checkouts, refunds, or customer IDs that changed in a migration. The DAX on this page is short; cleaning the customer key and agreeing the cohort definition is where most of the work sits.
Power BI Flex Support is prepaid, senior-led Power BI hours that never expire, with no contracts and no project minimums. Blocks are Starter $2,500, Growth $4,600 and Power $8,000, and hourly work starts from $100. You send the request, we reply with a scope and an hours estimate before any work, hours are deducted only for work you approve, and most tasks land 3–5 business days after approval. If the cohort is only the visible symptom of a tangled model, the same hours cover data modeling and DAX work. Contact is through the form on this site.
FAQ
Use the event that marks a real customer relationship. For a store that is the first paid order; for a subscription product it is usually the first invoice or trial conversion. Signup date mixes in people who never bought, which inflates cohort size and drags every retention percentage down. Pick one definition and document it on the report.
Matrix totals add up cohorts of different ages. The Month 3 column total blends cohorts that have reached month three with the rows that have not, and the row total simply reports each cohort as fully retained. Neither number answers a retention question, so turn subtotals off and show an average retention curve separately if you need one.
Yes. You can compute the first order date and the months-since index in Power Query with a Group By and a merge, then load them as ordinary columns. That keeps calculated columns out of the model and puts the logic upstream, where other reports can reuse it. The retention measures still belong in DAX so they respond to slicers.
Swap the distinct customer count for a sales measure. Revenue in a given month divided by the cohort revenue in Month 0 shows how much spend each cohort keeps, and it can exceed 100 percent when returning customers buy more. For subscription MRR with expansion and contraction, use a monthly MRR snapshot model instead.
Yes. A senior, US-based, Microsoft-certified engineer can build the cohort model and heatmap on your own order data from prepaid Flex hours that never expire. Blocks are Starter $2,500, Growth $4,600 and Power $8,000, with hourly work from $100. We quote the hours before starting, and most tasks land in 3 to 5 business days after approval.
If you’re unhappy within the first 4 hours of your block, we’ll refund you in full — no questions asked. Hours are deducted only for work you’ve reviewed and approved, and they never expire.
Bring your order or billing data to a free demo. We check the customer key, agree the cohort definition with you, and build the heatmap on prepaid hours that never expire. Most tasks land in 3–5 business days.
Scope approved before any hours are used · Hours never expire
Tell us the task. We scope it, you approve, and a senior consultant delivers — typically in 3–5 business days. Prepaid hours that never expire.