Skip to content
AnuragAnalytics
Go back

The Query Ran. The Answer Was Wrong: 9 Silent Traps in Analytics

12 min read

None of the worst mistakes I made this year threw an error.

Every one of them ran clean and produced a number that looked reasonable enough to put in front of a leader. That is what makes them dangerous. A query that crashes costs you five minutes. A query that runs and is wrong costs you a decision, and then your credibility when someone finds it.

I work on growth experimentation and analytics in e-commerce payments: A/B tests, customer segments, and the reviews where those numbers turn into decisions. For the past several months I have done most of that work alongside an AI assistant, and I kept a running ledger of every correction, pushback and logic change. It now has more than 250 entries. Most of them share one property: the output looked fine.

Below are the nine traps that came back most often, grouped by where they hide. Each comes with the tell that gives it away and the fix. The charts and worked examples use made-up numbers to show the mechanism; the few figures from my own work are ratios, not amounts.


Part 1: Traps in the SQL

1. Your database can round away your answer

In Redshift, writing x * 1.0 / y to get a decimal rate keeps the math in DECIMAL arithmetic, and depending on the inputs the result can come back with only four decimal places. A rate of 0.023456 (2.3456%) comes back as 0.0234 (2.34%).

Trap 1: Truncation is harmless on a rate and lethal on a difference

On a single rate, nobody notices. On the difference between two rates, it is lethal. Test effects are usually a few basis points (bps, hundredths of a percent), and the fourth decimal place of the fraction (0.0001) is exactly one bps. Truncate a 2.3401% holdout and a 2.3199% treatment and the gap jumps from 2.02 bps to 3.00 bps: half again as large, from rounding alone.

This one cost me a full day, and it had overstated an impact estimate by about 40% before I caught it. The same bug later put locations into the wrong risk deciles, because rates that differed only in the fifth decimal place became ties.

  • Fix: CAST(x AS FLOAT8) / NULLIF(y, 0)
  • Habit: Compute one rate by hand and check that the query returns it to the last digit.

2. A join at the wrong grain multiplies quietly

Two tables can both feel like “order data” and still sit at different grains. I once joined item-level refusals to item-level returns on the order ID instead of the item ID. Every return was copied onto every item in its order. No error, no warning, just more returns than ever happened, and a headline test result that moved noticeably once the key was fixed.

Trap 2: Join on the wrong key and two returns become six

The tell is the row count. Count rows before and after every join. If a join was supposed to add columns and it added rows, stop.

When you need an order-level number, like a fee, on an item-level table, do not join it at item grain. Park the full amount on one elected “carrier” row per order and put zero on its siblings, so SUM stays exact at every rollup. One trap inside the trick: apply your date filter before you elect the carrier. Otherwise an order that straddles the window boundary elects an out-of-window row, the filter deletes it, and the fee vanishes.

[items: 3 rows for order 1001] ──JOIN ON order_id──▶ [6 rows, SUM(returned) = 6]  ❌
[items: 3 rows for order 1001] ──JOIN ON item    ──▶ [3 rows, SUM(returned) = 2]  ✅

3. Decide what NULL means, or the data decides for you

A “new customer” flag built on first purchase date has two opposite meanings. If it means tenure (“how new is this shopper?”), a NULL first purchase means they have never bought anything: as new as it gets, so 1. If it means acquisition (“did we win this customer?”), a purchase must have happened, so NULL means not acquired: 0. Same column, opposite answer. I shipped the wrong one once, and because never-purchasers clustered in one test arm, it tilted the comparison.

Trap 3: Decide what NULL means, or the data decides for you

NULL also changes what your joins do. A LEFT JOIN followed by WHERE status <> 'x' silently drops every NULL row, because a comparison with NULL is never true. Your LEFT JOIN is now an INNER JOIN.

The same care applies to any cohort flag in an experiment: define it on behaviour from before the treatment could act. If the treatment changes who completes an order, a flag built on completed orders is already contaminated. Build it on checkout attempts instead.

  • Habit: On the line where a flag is defined, write down what NULL represents.

Part 2: Traps in the comparison

4. The blended rate moved because the weights moved

A blended rate is a weighted average. When it moves, either the segment rates moved or the mix moved, and the headline cannot tell you which.

Trap 4: Every segment improved. The blended rate got worse.

In the chart above, both customer segments improve from period 1 to period 2: the low-risk segment from 2.0% to 1.8%, the high-risk one from 10.0% to 9.5%. The blended rate still rises from 3.60% to 4.88%, because the high-risk segment grew from 20% to 40% of volume. Report the blend alone and you tell a leader that quality fell when it improved everywhere.

This is Simpson’s paradox, and in real data it hides in plain sight: a fast-growing low-risk channel that pulls clean volume out of the pool, or a city-tier “gradient” that disappears once you compare like-for-like customer cohorts within each tier.

  • Fix: Split every change into a mix effect (shares moved, rates held at period 1) and a rate effect (rates moved, at period 2 shares). The two add up exactly to the total. Here the +128 bps headline is +160 bps of mix and -32 bps of behaviour. Only the second number is about customers.

5. A pooled holdout invents effects

When two experiments overlap—say a product change and a reminder message reaching some of the same customers—adding their separate effects double-counts the overlap. The standard fix is to split customers into boxes (only A, only B, both), compare each box’s treatment with that box’s own holdout, and add up the units.

Trap 5: A pooled holdout turned a half-point mix gap into a 25% bigger effect

The tempting shortcut is one pooled holdout rate across all boxes. The boxes have very different baselines (2%, 9% and 16% in the example), so a pooled holdout blends them, and any small difference in box mix between the arms turns into an “effect”. In the example, a half-point mix difference inflates the answer by 25%. In my real work, the pooled version overstated the impact by 6.8% from arithmetic alone.

  • Rule: Units add up across boxes, and so does impact expressed in units or in bps of the whole. Rates and rate differences never do.

6. A shrinking holdout manufactures a spike

Experiments often dial up: the holdout shrinks from half of traffic to a sliver as confidence grows. In the weeks after the change, the gap between treatment and holdout can jump. It looks like the effect is accelerating. Usually it isn’t.

Trap 6: When the holdout shrinks, check which line moved

The tell is which line moved. If the holdout lurches while the treatment line stays flat, the spike came from the holdout: a much smaller group, and a differently composed one, since customers randomised after the change are not like the ones already in the test. A real change in effect shows up in the treatment line.

  • Habit: Plot both arms, never just the gap. Mark every dial change on the chart, and flag any period where holdout volume fell by more than half versus the period before.

7. Your A/B tool may measure the offer, not the product

Most experiment tools read customers in a window around a trigger event, such as being shown an offer. That breaks when accepting is permanent: once a customer opts in, they are in the product for good and stop generating new triggers.

Run that for a few months and the trigger stream fills up with whoever has not accepted yet. The best customers accepted early and left the read. What remains is a late-arriving, adversely selected group, and next to the holdout the product looks harmful. The tool is measuring who declines the offer.

Month 1: [100% still triggering]
Month 2: [~72% still triggering] [~28% accepted -> invisible to trigger read]
Month 6: [~25% still triggering] [~75% accepted -> invisible to trigger read]

Trigger read (leftovers only) ──▶ looks worse than Holdout over time
Carried-forward population       ──▶ true product effect across everyone
  • Fix: Measure the population, not the trigger stream. Carry every customer who accepted forward in the treatment group from the day they joined (the holdout, by design, never contains anyone who joined) and read outcomes across everyone. The honest caveat: this is a point-in-time read, and other launches land during it. Random assignment is what saves you. Anything concurrent hits both arms equally, so it cancels when you take the difference.

Part 3: Traps in the readout

8. The wrong rate hides the people you are hunting

To find risky customers, the obvious cut is their overall refusal rate. It dilutes. Take a customer with 10 cash-on-delivery orders, 5 refused at the door, and 40 prepaid orders with 1 refused. Their cash-on-delivery refusal rate is 50%. Their overall rate is 12%, and a 40% overall threshold never sees them.

Metric ScopeOrdersRefusalsRateFlagged at >= 40% Cut?
Cash on delivery10550.0%Yes (50% >= 40%)
Prepaid4012.5%No
Overall blended50612.0%No (hidden by 40 prepaid orders)

When I checked, a large share of the customers who were genuinely high-risk on one payment method looked ordinary on their overall rate, and they were exactly the group a policy change affected most.

  • Habit: Label on the rate of the behaviour you are acting on. Add a volume floor (for example, 5+ orders on that method) so one bad week does not brand a customer. And when you report it, name the rate in full every time: which rate, which window, which floor.

9. If a leader needs a glossary, the analysis isn’t finished

My first version of a deep-dive report had 72 tables. Every number was right and nobody could read it. The second version had 5 tables and was too condensed to trust. The version that landed used one rhythm per section: a one-sentence headline, one table, three to five bullets, and numbered actions at the end.

Readout VersionStructureFailure Mode
Version 172 tablesEvery number right; nobody reads it
Version 25 tablesToo condensed to trust
What landed1-sentence headline + 1 table + 3–5 bullets + numbered asksScannable, auditable, decision-ready

What I now do for every leader-facing readout:

  1. The answer goes on line one. Method comes after, if at all.
  2. Section titles are conclusions. “Did the price change hurt repeat purchase? No.” beats “Pricing analysis”.
  3. Name every rate in full. “Good customers” and “10%” mean nothing until you say which rate, over which window, with which minimum volume.
  4. Write “holdout”, not “control”, for non-technical readers. “Control” reads as everyday English and confuses.
  5. Say bps in words once (“-40 bps, or 4 fewer in every 1,000 orders”), then put the raw count beside it.
  6. State caveats up front, with a label. Moving a caveat to the end makes the claim look stronger than it is.
  7. Close with asks, not a summary.

What changed when I started working with an AI assistant

AI made me much faster at writing queries. Left unchecked, it also made me faster at being wrong, because it writes plausible SQL that runs. Some of the traps above came from AI-written code; some came from mine. What made the pairing work was process:

  1. Every correction becomes a written rule the assistant reads before the next task. A correction you have to repeat is a wasted correction. That is where the 250-entry ledger came from.
  2. No SQL from memory. The assistant searches our existing, proven queries for real table and column names before writing a line. An unverified column gets flagged, never guessed by analogy.
  3. A self-report is not verification. When an agent says “all checks passed”, the same misreading that caused a bug also hides it. Check independently: row counts, a hand-computed rate, a total you already know.
  4. Start from the proven query and debug only the change. Rewriting working code to fix one bug is how you get two new ones.
  5. Simple beats clever. Step-by-step temporary tables you can read top to bottom are easier to audit than nested subqueries, for people and for AI.

The checklist I run before a number leaves my laptop

  1. Compute one rate by hand and match it to the query, digit for digit.
  2. Cast to float before you divide.
  3. Count rows before and after every join.
  4. Write down what NULL means for every flag.
  5. Split every blended change into mix and rate.
  6. Compare each experiment box with its own holdout.
  7. Plot both arms, not just the gap, and mark every dial change.
  8. Ask whether your A/B tool can still see the customers who accepted.
  9. Count the independent unit. If people retry, significance per attempt overstates; on one of my tests it looked about 2.5 times stronger than it was.
  10. Put the answer on line one and name every rate in full.

Which silent trap has cost you the most? I’d like to add it to the list. Charts and worked examples use made-up numbers. Views are my own.



Previous Post
Inside the 35-Minute Promise: How Food Tech Giants Predict Delivery ETAs in Real Time
Next Post
When Lenskart's Sales Drop 12% MoM: A Senior Analyst's Playbook