Chapter 1 — Anatomy of Metrics

Retention: Did They Come Back?

18 min

Five cats and one calendar

Retention answers a question that neither DAU nor a can answer: did the same people come back?

To answer it, you need a —a group of users who share the same starting condition. In this lesson, the condition is the date of the first visit: for example, “everyone whose first visit was March 1.” A user enters this cohort once and stays in it for the entire observation period.

Here are five cats from the black box, along with the dates of their first visits and all later visits:

catfirst visitlater visits
LeoMarch 1March 2, March 8
SnowballMarch 1—
FluffyMarch 2March 3, March 9
MollyMarch 5March 6
GingerMarch 5March 12

Calendar dates make these cats hard to compare because each one started using the product on a different day. The comparison becomes useful when we switch from absolute dates to how long each user has been in the product.

A cadet and a robot cat watch a hologram in which groups of capsules follow the same timelines and some capsules return at checkpoints.
Retention is calculated against the cohort size, so calendar dates are converted into days since the first visit: D0, D1, D7.

Calendar → relative days

D0 is the day of the first visit. It does not mean “day zero of the month”; it means “day zero for THIS user.” Leo's D0 is March 1, while Molly's is March 5. From there, we count each user's days from their own D0.

The table marks only the dates when each cat visited. A dash means there was no visit that day.

catMarch 1March 2March 3March 5March 6March 8March 9March 12
LeoD0D1———D7——
SnowballD0———————
Fluffy—D0D1———D7—
Molly———D0D1———
Ginger———D0———D7

The same D1 falls on different calendar dates for different cats: March 2 for Leo and March 6 for Molly. The reverse is also true: March 8 is D7 for Leo but D3 for Molly, even though Molly did not visit that day. This conversion is the key idea behind : we align everyone by their own starting point and can then compare people who arrived on different dates.

Why not simply compare “how many users we had yesterday” with “how many we have today”? Total DAU mixes old and new users together. A product could lose every new user within a week and still grow in DAU if advertising brings in new users faster than old ones leave. Cohort analysis separates one specific group from the overall flow and lets us ask: did these cats come back?

CalendarAsignup Mar 1Bsignup Mar 5Csignup Mar 512345678MarchCohort ageAMar 1Mar 2Mar 8BMar 5Mar 6Mar 12CMar 5Mar 6Mar 12D0D1…D7retention is measured in cohort age, not on the calendar
Each user is aligned by their own D0: calendar dates become time since the first visit, so Leo's D1 lines up with Molly's D1.

The denominator is the original cohort

Now we'll calculate for our five cats.

The March 1 contains Leo and Snowball, so its size is 2. On D1, only Leo came back → D1 retention = 1 / 2 = 50%. On D7, only Leo came back again → D7 = 50%.

The March 5 cohort contains Molly and Ginger, so its size is 2. Molly came back on D1 → 50%. Ginger came back on D7 → 50%. Notice that these are different cats. Retention does not require the same person to return at every checkpoint: each checkpoint measures its own share of the same original cohort.

At real-world scale, it looks like this:

Cohort 'arrived March 1': 1000 cats ← DENOMINATOR for every checkpoint
  active March 2 (D1):   380  → D1 = 380 / 1000 = 38%
  active March 8 (D7):   190  → D7 = 190 / 1000 = 19%
  active March 31 (D30):  90  → D30 = 90 / 1000 = 9%

This is the rule behind many incorrect retention calculations:

The denominator is always the original cohort—the same 1000 people—not however many are left.

You might be tempted to divide the 190 users active on D7 by the 380 active on D1, which gives 50%. But that number cannot be interpreted as “half of the users who returned on D1 also returned on D7”: these totals do not tell us how many cats were active on both days. To calculate that share, the numerator would need to be the number of cats active on both D1 and D7, and the denominator would be the 380 cats active on D1. That is a different metric, and we do not have the data to calculate it here. Regular D7 retention is still 190 / 1000 = 19%.

A fixed denominator has another consequence: retention at individual daily checkpoints does not have to decrease monotonically. Someone can skip D1 and return on D7, as Ginger did. D7 can therefore be slightly higher than D3, especially if day seven falls on a weekend or coincides with a messaging campaign. A always decreases; this kind of retention does not.

Two decisions to make before you calculate

Decision 1: what does “came back” mean?

As with “active” in the DAU lesson, the phrase “came back” does not define a metric by itself. For the same March 1 :

definition of “came back”returned on D1D1
any event in the log45245.2%
opened the app (app_open)38038.0%
placed an order (purchase)616.1%

The values differ by more than sevenfold, and all three definitions are valid. For a game, opening the app can be a sensible definition of a return. For a marketplace, you might choose an order if you want to track purchases after the first visit, or an app open if you are studying regular product usage. An order is more closely tied to revenue but happens less often. Choose the definition deliberately, document it, and do not change it without saying so.

Decision 2: “exactly on day N” or “on day N or later”

These are two different kinds of retention, and they produce different numbers.

Exact-day (classic) retention. D7 is the share of the cohort that was active exactly on the seventh day. This is a strict, sensitive metric: if someone visited on D6 and D8 but skipped D7, they do not count toward D7 retention. It works well for comparing cohorts and is common in mobile analytics. Throughout this course, DN always means this type of retention.

Rolling (unbounded) retention. D7 is the share of the cohort that had activity on the seventh day OR later. This definition answers “is this person still around?” rather than “did they visit on one specific day?” Its value is never lower than exact-day retention and usually changes more smoothly. Rolling retention also depends on when the data is collected: if someone comes back later, a previously calculated value can increase.

March 1 cohort, cat visited on March 2 and March 9
  exact-day D7 (March 8): NOT counted — the cat was absent that day
  rolling  D7:            counted — March 9 is later than day seven

Neither type is “more correct.” You need to know which one a report uses and avoid comparing the two as if they were the same metric. If D7 differs twofold between two reports, check the retention definition before looking for a change in the product.

Immature cohorts: an empty cell is not zero

Today is March 14. Consider two .

February 1 cohort. In the year 2184, February has 29 days, so this cohort's D30 falls on March 2. That day has already passed, the data has been collected, and the value is known.

March 10 cohort. Its D1 (March 11) is known. Its D7 falls on March 17, and that day hasn't happened yet. Its D30 falls on April 9.

             D1     D7     D30
February 1   41%    22%    11%
March 10     39%     ?      ?     ← not reached yet

The question mark is not zero. Zero would mean “nobody came back,” which would be a disaster. Here it means “we don't know yet”: the cohort is immature because not enough calendar time has passed.

In tables and code, this kind of “unknown” value is usually represented by a special value. In pandas, that's NaN (not a number), and we'll cover it in detail in the chapter on dirty data. For now, remember this rule:

NaN ≠ 0. You can't replace an unknown value with zero: skip it or handle it separately in calculations, and leave a gap in a chart instead of drawing a drop to zero.

Here's what can go wrong in practice. If you calculate average D7 across all cohorts and replace immature values with zeros, the average will drop sharply and create a “ decline” that does not exist. If you replace empty D30 values with zeros before plotting a line, the line will fall toward the most recent dates simply because those cohorts do not have D30 data yet.

Investigator's rule: when comparing cohorts, include only those that have reached the age you're measuring. Want to compare D30? Look only at cohorts at least 30 days old and leave the rest blank. For an earlier signal without trying to predict the future, use D1, D3, or D7 if those checkpoints have already matured for every cohort in the comparison. They can reveal changes sooner, but they do not replace D30.

The March 1 cohort in the calculator. Notice that all three formulas use the same denominator: 1000. The last line calculates a different metric—survival from D1 to D7. As discussed above, you cannot calculate it from aggregate totals alone because we do not know how many cats were active on both D1 and D7. Here we make the assumption explicit: all 190 cats active on D7 are assumed to have been active on D1 as well.
python
Practice: write the code
March 3 cohort: 800 new cats. Exactly 296 were active on March 4 (D1), and exactly 120 were active on March 10 (D7). Calculate d1 and d7 as percentages. Watch the denominator: it is the same at both checkpoints.
python
Practice: write the code
Use the same March 3 cohort (800 cats, 296 on D1, 120 on D7; as in the calculator, assume that all 120 cats active on D7 were also active on D1). Calculate two values that are easy to confuse with retention: survival_d1_to_d7—the share of D1 returners who made it to D7—and churned_by_d7—the number of cats from the ORIGINAL cohort who were not active on D7.
python
Check yourself
The March 1 cohort has 1000 people. 380 returned on D1, and 190 were active on D7. What is D7 retention?
Check yourself
Today is March 14. In the table, D30 for the March 10 cohort is empty. A colleague suggests entering 0 “so the average can be calculated.” What's wrong with that?
Key takeaways
  • a is a group of users with the same first-visit day; each user enters it once and stays in it forever
  • D0 is the day of a specific user's first visit; calendar dates are converted into user age, so different users are aligned by their own starting points
  • the denominator in is always the size of the original cohort; 190 / 380 without data on the overlap between users active on D1 and D7 is just a ratio of two , not D7 retention
  • “came back” must be defined in advance: any event, an app open, or an order will produce different results
  • exact-day DN (“exactly on day N”) and rolling DN (“on day N or later”) are different metrics; you can't directly compare them as if they were the same metric
  • immature cohorts stay empty: NaN ≠ 0

Next up: the cohort table—how all these rows fit into a single grid and what to look at first.