Chapter 1 · 7 levels

Revenue and orders

Gross sales, discounts, net sales and net revenue, average order value and units per order, what coupons cost and how returns eat into the top line, on three years of Harbor & Pine orders.

Start

“What was revenue last year?” sounds like the easiest question an analyst gets. It has at least four honest answers, and the one you give depends on which orders you count, whether discounts and refunds come off, and whether shipping is in. Most revenue arguments in a meeting are two people using different definitions of the same word.

This track uses one set of house definitions, the same in every chapter, so every number you compute can be compared with every other:

  • Valid line: order_items.quantity > 0. The 24 lines with zero or negative quantity are data-entry errors and are left out.
  • Line gross = quantity * unit_price (the price paid on the line). Line discount = line gross × discount_pct / 100. Line net = gross − discount.
  • Booked order: status IN ('completed', 'refunded'), the orders a customer actually paid for. Cancelled orders were never paid; pending ones have not settled yet. A refunded order was paid and then sent back in full.
  • Gross sales = Σ line gross on booked orders. Net sales = Σ line net on booked orders. Refunds = Σ returns.refund_amount (returns join order_items on order_item_id). Net revenue = net sales − refunds. Shipping fees are not revenue here.
  • Year windows: order_date >= '2025-01-01' AND order_date < '2026-01-01'. Refunds count in the year of the order they belong to.

Code levels alternate between SQL and pandas; the tag on each level says which. The boss is a 2025 revenue bridge your Head of Finance can put in front of the board.

Levels

  1. Gross sales, discounts, net sales

    from Laura Bennett, Head of Finance

    gross sales, net sales, discounts, revenue definition

    Code Difficulty 1 of 5 Not started

  2. Which orders count?

    from Megan Collins, Head of Sales

    order status, revenue definition, booked orders, refunds

    Quiz Difficulty 1 of 5 Not started

  3. AOV and units per order

    from Catherine Hale, Chief Executive Officer

    aov, units per order, groupby, nunique, ratio metrics

    Code Difficulty 2 of 5 Not started

  4. What the coupons cost

    from Jordan Reyes, Head of Marketing

    discounts, coupons, share of total, window functions

    Code Difficulty 2 of 5 Not started

  5. From net sales to net revenue

    from Anthony Ramos, Financial Analyst

    refunds, net revenue, return rate, merge, left join

    Code Difficulty 2 of 5 Not started

  6. Metric trap: the average discount rate

    from Laura Bennett, Head of Finance

    ratio of totals, average of ratios, weighting, discount rate

    Quiz Difficulty 3 of 5 Not started

  7. Boss: the 2025 revenue bridge

    from Laura Bennett, Head of Finance

    revenue bridge, net revenue, aov, refund rate, left join, cte

    Boss · 3 steps Difficulty 3 of 5 Not started

Pick what may run on this site. You can change this any time from "Cookie settings" at the bottom of every page.