Quick answer
Turn a business question into a calculable KPI by specifying the decision, numerator, denominator, eligible population, time window and data grain before building a report. Then test the definition on a small dataset.
For example, replace “Are customers coming back?” with “What percentage of customers who made their first qualifying purchase in January made another qualifying purchase within 30 calendar days?”
A formula is only part of a metric’s definition. You also need rules that let another analyst select the same records and reproduce the same result.
This guide uses a small, synthetic purchase dataset. You can follow the calculations with a spreadsheet or by hand; no SQL, Python or business intelligence software is required.
1. Start with the decision, not the dashboard
Write down what someone might do differently after seeing the result.
Consider this question:
“Are customers coming back?”
Before choosing a metric, ask what the reader actually needs to decide:
- Whether to investigate the experience after a first purchase.
- Whether returning buyers account for more of this month’s customers.
- Whether a particular group of newly acquired customers buys again.
Those questions require different counting rules.
For this tutorial, suppose the intended decision is:
“Should we investigate why recent first-time buyers do not make a second purchase?”
A suitable measurement question is:
“Among customers whose first qualifying purchase occurred in January, what percentage made another qualifying purchase within 30 calendar days?”
This focuses on new customers’ subsequent behavior rather than the composition of all buyers in January.
Practical check: finish this sentence before proceeding:
“We will use this KPI to decide whether to ______.”
If you cannot complete it, clarify the question before spending time on a chart. Also record who will review the result and what additional evidence they would need before acting. Leave names and targets unassigned until someone actually agrees to them.
2. Define exactly what goes above and below the line
For the customer percentage in this example:
KPI = qualifying repeat customers ÷ eligible first-time customers × 100
The numerator counts customers who meet the repeat-purchase condition. The denominator counts customers who were eligible to meet it.
Write both as complete sentences:
- Numerator: distinct eligible customers who made a later qualifying purchase within the specified follow-up window.
- Denominator: distinct customers whose first qualifying purchase occurred during the specified enrollment period and whose full follow-up window is observable.
Here, “distinct” means each customer counts once, regardless of how many orders they placed. Every customer in the numerator must also belong to the denominator.
Do not assume a familiar metric label supplies these rules. For example, Shopify’s official reference defines returning customer rate as returning customers divided by customers who placed orders. That denominator differs from a group restricted to first-time January buyers. (help.shopify.com)
Give your metric a descriptive name, such as January first-purchase cohort: 30-day repeat-purchase percentage.
For the synthetic example below, a qualifying purchase is a completed, non-cancelled, non-test order that has not been fully refunded at the reporting cutoff. These are tutorial rules, not a universal commercial definition. A real implementation must confirm whether its data can support them.
3. Separate the population, enrollment period and follow-up window
The population answers “Who is eligible?” Specify any channel, region or customer restrictions, along with how you handle missing customer identifiers.
For this example, the population is customers with stable IDs in the synthetic order history. All their qualifying purchases are included.
Next, distinguish two clocks:
- Enrollment period: first qualifying purchase from January 1 through January 31, 2026.
- Follow-up window: a later purchase on calendar days 1–30 after each customer’s first purchase.
A cohort is a group defined by a shared characteristic. Google’s cohort documentation similarly separates the condition that includes someone in a group from the subsequent condition used to measure their return. (support.google.com)
For this tutorial, dates use UTC. Same-date additional orders do not count as repeats, while an order exactly 30 calendar days later does.
That boundary is a choice. If you want same-day repeat orders or an exact 720-hour window, specify that instead.
Do not classify a customer as a non-repeater before their observation window finishes. A January 31 buyer has not had 30 days to return when January ends. In the example, the data is complete through March 5, 2026, so every January entrant has finished follow-up.
Also distinguish first purchase ever from first purchase visible in your extract. If earlier history is unavailable, use “first observed purchase” and state the limitation.
4. Check what one row represents before counting anything
Data grain means what one row represents.
For this calculation, keep three levels separate:
| Level | One row represents | Purpose |
|---|---|---|
| Order line | One product line within an order | Inspect purchase details |
| Order | One qualifying order | Identify purchase events |
| Customer | One eligible customer | Calculate the customer percentage |
A useful real-world practice dataset is UCI’s Online Retail dataset. Its documentation lists invoice IDs, product codes, product quantities, invoice dates and customer IDs. Those fields describe product-level purchase records, not a ready-made table of one row per customer. (archive.ics.uci.edu)
If an invoice contains several product lines, those lines must not become several purchases merely because they occupy several rows.
For the tutorial, prepare a customer table containing:
- Customer ID.
- First qualifying purchase date.
- Second qualifying purchase date, if present.
- Number of qualifying January orders.
- Cohort eligibility and repeat-purchase flags.
Before aggregating, check that each order maps to one customer and one purchase date under your chosen rules. After joining other tables, compare distinct order and customer counts with their pre-join values. Investigate unexpected changes.
For UCI practice work, its documentation identifies invoice codes beginning with “c” as cancellations. Use that documented signal, but do not assume the dataset proves every completed-order or refund condition in your specification. (archive.ics.uci.edu)

5. Work through three definitions using the same customers
The following dataset is synthetic. It contains no actual business results.
Assume the purchase history is complete, every listed order qualifies, and observation continues through March 5, 2026. Blank second-purchase dates mean no second qualifying purchase was observed by that cutoff.
| Customer | First purchase | Second purchase | January orders |
|---|---|---|---|
| A | January 3, 2026 | January 20, 2026 | 2 |
| B | January 10, 2026 | February 5, 2026 | 1 |
| C | January 20, 2026 | March 1, 2026 | 1 |
| D | January 31, 2026 | — | 1 |
| E | December 15, 2025 | January 12, 2026 | 1 |
| F | January 25, 2026 | — | 1 |
Definition A: customers with at least two January orders ÷ January buyers
All six customers bought in January. Only A placed at least two orders during January.
1 ÷ 6 × 100 = 16.7% rounded
This measures repeat purchasing inside one calendar month.
Definition B: January buyers who placed an order after an earlier purchase ÷ January buyers
A’s January 20 order follows an earlier purchase. E’s January 12 order also follows an earlier purchase, although E’s first purchase was in December.
2 ÷ 6 × 100 = 33.3% rounded
This measures the returning-customer share of January buyers under the stated rule.
Definition C: January first-time buyers who repeat within 30 days ÷ January first-time buyers
A, B, C, D and F belong to the January first-purchase cohort. E does not.
- A repeats after 17 days: included.
- B repeats after 26 days: included.
- C repeats after 40 days: excluded.
- D and F have no observed second purchase: excluded from the numerator.
2 ÷ 5 × 100 = 40%
This answers the tutorial’s decision question.
To reproduce it, mark January first-time buyers, subtract first-purchase date from second-purchase date, and flag eligible customers with a gap from 1 through 30 days. Count flagged customers and divide by eligible customers.
All three results are valid for their definitions. They are not interchangeable.
6. Save a reusable KPI specification and validation checklist
Copy this template before implementing another metric:
| Specification field | What to record |
|---|---|
| Name and version | Descriptive name; definition version |
| Business question | The question the metric answers |
| Decision supported | What someone may do with the result |
| Numerator | Exact event or customer counting rule |
| Denominator | Exact eligibility and counting rule |
| Population | Channels, regions, customer types and exclusions |
| Time rules | Enrollment, follow-up, timezone and boundaries |
| Source and grain | Tables or files; meaning of each row |
| Keys | Customer and order identifiers; uniqueness rules |
| Quality handling | Missing IDs, duplicates, cancellations and refunds |
| Reporting | Unit, rounding, cutoff and refresh schedule |
| Review | Responsible reviewer and agreed action criteria |
| Limitations | History gaps, incomplete follow-up and identity uncertainty |
Then run these checks:
- Subset: every numerator customer belongs to the denominator.
- Uniqueness: each eligible customer appears once in the final calculation table.
- Boundaries: manually test same-date, day-30 and day-31 purchases.
- Completeness: every included customer has finished follow-up.
- Identity: count records excluded because customer IDs are unusable.
- Reconciliation: trace a small selection of customers back to their orders.
- Empty population: report “not available,” not 0%, when the denominator is zero.
- Comparability: do not silently change a definition between reporting periods.
Display the underlying counts alongside the percentage: 40% — 2 of 5 eligible customers.
When combining groups, add their numerators and denominators before dividing. A simple average of percentages gives equally weighted groups a different calculation, which may not answer your customer-level question.
7. Report what the KPI shows—and what it cannot prove
For this example, an accurate summary is:
“In the synthetic January 2026 first-purchase cohort, 2 of 5 eligible customers made another qualifying purchase within 30 calendar days: 40%.”
That statement identifies the population, outcome, window and counts.
It does not establish that a campaign, website change or customer-service intervention caused the result. NIST distinguishes correlation from causality and explains that an association can reflect another factor; designed experiments provide a systematic way to investigate causal relationships. (itl.nist.gov)
Treat a change in the KPI as a prompt for investigation. First verify that definitions, data coverage and follow-up windows are comparable. Then examine possible explanations rather than choosing the most convenient one.
If the question is whether an intervention caused improvement, plan an appropriate evaluation—potentially a randomized comparison where feasible—and define its outcome in advance. The KPI specification helps make the outcome reproducible; it does not supply the causal evidence.
Your next step: take one business question, complete the specification, and calculate it manually for a few records. Resolve ambiguous cases before automating the report.
