AAmit’s LibraryLEARN · PRACTISE · REFLECT

Six orders, three ways to check a business decision

Question: A report says Referral has the highest contribution. Can we trust the number, and should we increase the campaign budget? First calculate it, then verify it, then decide what evidence is still missing.

Before you start: You need basic arithmetic. The case is fictional; currency units (CU) have no real-world value. The SQL and Python checks are optional for the worked calculation.

Fictional source orders and amounts
OrderChannelUnitsPrice per unit (CU)Revenue (CU)Contribution (CU)
101Search210206
102Search110102
103Referral3103010
104Referral1202012
105Referral2204026
106Direct110102
Total1013058

Calculate it: from order to margin

Every unit costs 6 CU to supply and every order costs 2 CU to handle. For order 105, the contribution is 2 × 20 − (2 × 6 + 2) = 26 CU. Across all six orders, the variable costs are 72 CU and the contribution is 58 CU. The contribution margin rate is 58 ÷ 130, about 44.6%. Divide totals rather than averaging order percentages: a 10 CU order and a 40 CU order should not have identical weight. If the shop has 40 CU in fixed costs and no other costs, the simplified profit is 18 CU. Contribution and profit answer different questions.

Verify it: reconcile SQL with Python

The orders table has one row per order. A new touch-events table has one row per event. Every order has one event except order 105, which has a referral and a follow-up. An ordinary join now counts order 105 twice: 170 CU revenue and 84 CU contribution, even though the shop sold the same six orders.

Summarize events by order first. This preserves seven events as seven events, rather than mistaking them for seven orders.

Optional: set up the six orders and seven events in a blank SQLite session
CREATE TEMP TABLE orders (id INTEGER PRIMARY KEY, units INTEGER NOT NULL, price INTEGER NOT NULL);
CREATE TEMP TABLE touches (event_id INTEGER PRIMARY KEY, order_id INTEGER NOT NULL);
INSERT INTO orders VALUES (101,2,10),(102,1,10),(103,3,10),(104,1,20),(105,2,20),(106,1,10);
INSERT INTO touches VALUES (1,101),(2,102),(3,103),(4,104),(5,105),(6,105),(7,106);
WITH touch_counts AS (
  SELECT order_id, COUNT(*) AS touch_count
  FROM touches
  GROUP BY order_id
)
SELECT COUNT(*) AS orders,
       SUM(o.units * o.price) AS revenue,
       SUM(o.units * o.price - (o.units * 6 + 2)) AS contribution,
       SUM(COALESCE(t.touch_count, 0)) AS touches
FROM orders o
LEFT JOIN touch_counts t ON o.id = t.order_id;

Independently sum the six source rows in Python, without looking at the joined table. The following list contains one (units, unit price) pair for each row in the table:

orders = [(2, 10), (1, 10), (3, 10), (1, 20), (2, 20), (1, 10)]
revenue = sum(units * price for units, price in orders)
contribution = sum(units * price - (units * 6 + 2) for units, price in orders)
assert (len(orders), revenue, contribution) == (6, 130, 58)

Data quality: a missing record is not a zero

Check the row IDs before you calculate anything. The six order IDs should each appear once in the source. Two different event IDs for order 105 are valid; two identical event IDs may be a duplicate and should be investigated. When one order has no recorded touch, its revenue should still be included. A left join retains it. The SQL counts zero recorded events for that row, which does not prove there was no customer contact. If all events for a whole day are missing after a tracking outage, label that day unknown for campaign attribution rather than claiming there were zero interactions. The order totals can still be complete while the attribution data are incomplete.

Decide: separate observed results from what the campaign caused

Referral contributed 48 CU across three orders. That shows what these records contain. It does not tell us what would have happened without a campaign: the Referral orders also have a different mix of prices, and there is no comparison group in the six orders.

In a separate planning scenario, suppose a test campaign costs 90 CU and each genuinely additional order is expected to contribute 10 CU. The break-even threshold is nine extra orders. If a properly designed comparison suggests six extra orders, the point estimate is −30 CU. If a plausible range is five to twelve, the implied range is −40 to +30 CU under the same assumption. Do not report certainty from that range or treat planning values as observations from the six orders. The next action is to compare similar eligible groups over the same window, use actual contribution and returns, and report uncertainty before expanding spend.

Go deeper: calculus for a small change in spend

The break-even calculation asks whether to run a fixed 90 CU campaign. A different question is whether to spend a little more near the current budget. Let B be campaign spend and n(B) be the expected number of incremental orders at that spend. Then expected campaign contribution after spend is P(B) = 10 × n(B) − B. For a smooth local approximation, the derivative is P′(B) = 10 × n′(B) − 1.

Suppose independent evidence suggests that, near 90 CU, one more CU buys 0.07 expected extra orders. Then P′(90) ≈ 10 × 0.07 − 1 = −0.30 CU per additional CU spent. So a small increase in spend is expected to reduce the result. To make a small increase pay off under these assumptions, the marginal response must exceed 0.10 additional orders per CU. Fractions here describe expectations across comparable runs, not fractions of an actual order. The response slope is hypothetical and not estimated from the six orders. Do not extrapolate this slope far from the current budget.

Go deeper: probability for the risk of losing money

For illustration only, assume there are two outcomes in a planning model: 5 extra orders with probability 60%, or 12 with probability 40%. Their results after campaign cost are −40 and +30 CU. The expected result is 0.60 × (−40) + 0.40 × 30 = −12 CU. The probability of covering the cost is 40% under this model. Those are different questions: an average result does not say how often you will break even. The two probabilities are assumptions, not confidence levels or conclusions from a six-order sample.

Practice and answers

  1. Math: If order 105 had three events instead of two, what would naive revenue and contribution be? 210 CU and 110 CU. The independently reconciled totals do not change.
  2. SQL: Why not use SUM(DISTINCT units * price) to correct the inflated revenue? Orders 101 and 104 both earn 20 CU, and orders 102 and 106 both earn 10 CU. Deduplicating amounts discards real sales; preserve the order ID instead.
  3. Statistics and Business: If a dashboard attributes 12 orders to a campaign, does that show it crossed the nine-order threshold? No. Estimate orders above the comparison baseline and check their contribution before drawing that conclusion.
  1. Calculus: At a local response of 0.12 orders per extra CU, what is the marginal result? +0.20 CU per extra CU, under the same margin assumption.
  2. Probability: What if the two stated outcomes were equally likely? −5 CU expected result and a 50% chance of covering the cost.

Glossary: Grain is what one row represents. Reconciliation checks a result against an independent source. Contribution is revenue less variable costs. Incremental orders are orders the campaign generated above the expected baseline, not merely orders credited to it by a tracking rule.