Population
Which customers, orders or events are eligible?
A metric is not just a formula. It is a business agreement about population, timing, grain, exclusions and meaning.
If two analysts can calculate the “same” KPI and get two defensible answers, the problem is usually definition, not SQL.
Growth reports $1.42M. Operations reports $1.36M. Finance reports $1.18M. All three dashboards say “Revenue.”
None of those numbers has to be wrong. Growth may be showing order value before refunds, Operations may be showing completed-order value, and Finance may be showing recognized net revenue.
The failure is that the metric name hides the business logic.
Which customers, orders or events are eligible?
What exactly are you counting or summing?
What is the comparison base for a rate?
Which timestamp assigns activity to a period?
At what level is the metric reported and compared?
What happens to refunds, fraud, tests and late data?
Never accept a metric name as a definition. Ask what population, event and denominator produce it.
The denominator is the population that could have produced the outcome.
The numerator did not change. The story changed because the denominator did.
A metric contract does not need to be bureaucratic. It needs to make the important choices visible enough that another analyst — or an AI agent — can reproduce the same answer.
Placed orders and completed orders are different operational stories.
GMV, gross revenue, net revenue and recognized revenue are not interchangeable.
Visitors → checkout and checkout → order answer different questions.
Weekly active retention, repeat purchase and subscription renewal are different metrics.
Signup date, first order attempt and first completed order create different populations.
Inactivity, cancellation and non-renewal require different definitions by business model.
| Metric | Definition | Time basis | Important rule |
|---|---|---|---|
| Completed Orders | Distinct order_id with final status = completed | completed_at | Exclude test/fraud orders |
| Cancellation Rate | Cancelled eligible orders / placed eligible orders | created_at cohort | Use final order status |
| Gross Merchandise Value | Sum of item value before refunds | completed_at | State tax/fees treatment |
| Net Revenue | Recognized revenue after refunds/discount rules | finance recognition date | Finance-owned definition |
| Average Order Value | GMV / completed orders | same window as GMV | Same order eligibility as denominator |
| Repeat Rate | Customers with 2+ qualifying orders / active customers | customer cohort + observation window | Define qualifying order |
An AI assistant can generate the formula quickly. It cannot infer which of several legitimate business definitions your company has agreed to use unless you provide that context.
I need to calculate weekly cancellation rate.
Metric contract:
- Eligible order: a non-test, non-fraud order that reached the placed state
- Numerator: distinct eligible order_id whose final status is cancelled
- Denominator: distinct eligible placed order_id
- Reporting cohort: order created_at week
- Final status: latest status event by event_time
- Recent periods may be incomplete because status events arrive late
- Output grain: week × city × customer_type
Before writing SQL:
1. Restate the metric contract.
2. Identify any ambiguity or missing rule.
3. Explain how the denominator will remain stable.
4. Explain how final status is derived without duplicating orders.
5. Then write SQL and provide validation queries. What business decision will this metric influence?
What is the numerator?
What is the denominator?
What event timestamp assigns the metric to a period?
What is the grain of the reported result?
Which rows are included or excluded?
How do refunds, cancellations and late-arriving events behave?
Who owns the definition when teams disagree?
Keep the same numerator but swap the denominator and watch the cancellation story change completely.
Start with the decision and competing hypotheses.
Understand grain, keys and relationships.
Use SQL as a testable transformation workflow.
Turn KPI names into reproducible metric contracts.
The foundation of analytics is not a dashboard. It is shared meaning: a clear question, a trustworthy data model, a reproducible query and an agreed metric definition.