Kevin Y

Episode 3,

We hit 112% of target. Then we checked.

Friday, 4:40 at Larkspur: Greg announces 112% of target and orders a cake. Kevin asks to look first.

In this episode

Data Team takes place at Larkspur, a fictional online home-goods retailer. The people are made up; the data problems are real.

  • Kevin, Head of Data

    Kevin

    Head of Data

    The calm one, talking to camera. Played by me; off screen I am a Data Solutions Architect.

  • Marisol, CFO

    Marisol

    CFO

    Wants one number, by Thursday. Never wrong about the business.

  • Greg, VP Sales

    Greg

    VP Sales

    Chases the deck and the shiny tool. Loves anything labelled AI.

  • Theo, Junior analytics engineer

    Theo

    Junior analytics engineer

    Eager, fast, breaks things on Fridays. Learns something every episode.

  • Ana, Data engineer

    Ana

    Data engineer

    Quiet, sees everything, gets one line per episode. It lands.

  • Pip, The AI assistant

    Pip

    The AI assistant

    Confident, fluent, sometimes wrong. Not the chat in the corner: that one only knows my CV.

What really happened

Theo added refunds to the revenue model so it would report net revenue. Refunds should make revenue go down. Revenue went up.

The join from orders to refunds ran on order_id, and one order can have several partial refunds. An order with three refunds matched three times, so its total was added three times: $600 × 3 − $100 = $1,700 instead of $500.

Nothing failed, because nobody had written down what one row of the revenue model means. The payments system disagreed by $380K, and that is how it was found.

The fix: sum the refunds per order first, join one to one, and add a test that the model has exactly as many rows as the orders table.

The lesson: Know the grain on both sides.

Run the 112% bug

Net revenue is gross minus refunds, one row per order. Some orders have several partial refunds. Pick what the orders join to, then run it. The query runs in your browser on DuckDB with 2,000 synthetic orders and 616 refunds.

with refunds_per_order as (
  select order_id,
    sum(amount) as amount
  from stg_refunds
  group by order_id
)
select o.order_id,
  o.gross_amount
  - coalesce(r.amount, 0)
  as net_amount
from stg_order_totals as o
left join  as r
  on r.order_id = o.order_id

Source, tests and the agent skill: github.com/Kevin-yyuan/dbt-reconcile

Go deeper

More about Kevin Y