Power BI trap #3
Commission = IF([Sales] >= 1000000, [Sales] * 0.05, 0)
every rep's row is right. they add up to 2,21,250.
the total row says 3,37,500.
the total doesn't sum the rows. it reruns the IF on all sales.
fix: SUMX(VALUES(Sales[Rep]), IF(...))
SQL traps #7
LAST_VALUE(amount) OVER (PARTITION BY customer_id ORDER BY ordered_at)
isn't the latest order. with ORDER BY and no frame, the window ends at this row.
win-back list: 127 customers. real: 45.
fix: FIRST_VALUE(amount) ... ORDER BY ordered_at DESC, id DESC.
pandas traps #1
df.groupby("region")["amount"].sum()
regions added up to 2,810,909. the real total was 3,231,063.
groupby drops NaN keys by default. 158 orders from 3 unmapped stores, gone. no warning.
use dropna=False, and check groups sum to the total.
5 checks before any number leaves my screen:
1. COUNT(*) before and after every join
2. COUNT(*) vs COUNT(col) before AVG
3. check the first and last day of the range
4. tie the total to someone else's number
5. say the result out loud as one sentence
each one cost me once.
SQL traps #6
SELECT ... FROM online_orders
UNION
SELECT ... FROM store_orders
came back 1,959 orders. there were 2,400.
UNION stacks, then removes duplicate rows. same day, same product, same price = one row kept. 441 orders gone, no error.
default to UNION ALL.
Spreadsheet traps #1
=VLOOKUP(B2, Products!A:C, 3)
7 of 10 prices came back wrong. the monitor cost 349. no error.
the missing 4th argument defaults to TRUE: approximate match on an unsorted list. add FALSE. every time.
Power BI trap #2
% of Total = DIVIDE([Sales], [Total Sales])
every region shows 100%.
on the North row, "Total Sales" is filtered to North too. the name doesn't change what it sees.
denominator needs CALCULATE([Sales], ALL(Sales[Region])). no error until then.
SQL traps #5
SELECT ROUND(AVG(discount), 2) FROM orders
came back 176.40. the real per-order number was 44.10.
AVG skips NULLs. 1,000 orders, 250 had a discount. it divided by 250, not 1,000. no error.
put COUNT(*) next to COUNT(discount) before you trust any average.
8 things i stopped doing this year:
1 charts with no sentence under them
2 "the data shows"
3 dashboards nobody asked for
4 totals without a row count
5 answering the question as asked
6 fixing it in Excel, not the query
7 definitions in my head
8 saying yes to "quick"
a PR titled "fix: duplicate rows". the whole change: SELECT became SELECT DISTINCT.
before: 2,202 rows, revenue 1.79 cr (a join fan-out).
after: 667 rows, 49.4 L.
real: 1,000 orders, 65.7 L.
DISTINCT didn't fix the join. it hid it, and deleted 333 real orders on the way.
SQL traps #4
WHERE order_date BETWEEN '2026-09-01' AND '2026-09-30'
september came back with 29 days.
'2026-09-30' on a DATETIME column means midnight. every order placed on the 30th is dropped. no error.
use >= '2026-09-01' AND < '2026-10-01'. always.
asked four teams what "active customer" means.
sales: bought in last 12 months. 18,412
finance: invoiced this FY. 11,206
product: logged in last 30 days. 7,930
support: live contract. 9,114
all four on slides the same week. nobody was wrong. nobody wrote it down.
Power BI trap:
Target = 1,50,00,000 for North. South. East. West. total: 1,50,00,000.
the total is right. every row is wrong.
no relationship to Targets, so the row filter never arrives. the measure returns the grand total everywhere.
same number on every row = fix the model.
inherited a 412 line SQL query. "do not touch, ask Karan." Karan left.
what i asked AI:
explain it one CTE at a time
where does each output column come from
list every filter and the rule behind it
what breaks if i delete CTE 6 (nothing)
writing SQL is cheap. reading it isn't.
stakeholder requests, translated
"can you just add one filter" β the model needs a new table.
"quick sanity check?" β redo it all, faster.
"the number looks off" β it's lower than expected.
"roughly, no need to be exact" β quoted to the CEO as fact.
which did i miss? π
SQL traps #3
SELECT SUM(o.amount)
FROM orders o
JOIN order_items i ON i.order_id = https://t.co/yBceAXBHvX
27.3 L from orders. 53.3 L through that join.
an order with 3 items became 3 rows. SUM counted it 3 times.
check COUNT(*) vs COUNT(DISTINCT https://t.co/yBceAXBHvX)
first hour with a new dataset, i don't ask AI for a single chart.
i ask:
one row per what?
which columns are empty?
where are the duplicates?
did any column change meaning halfway?
your analysis is only as good as your understanding of the data.
SQL traps #2
LEFT JOIN orders o ON o.customer_id = https://t.co/4vyCUFdRKg
WHERE o.order_date >= '2026-01-01'
congrats, that's an INNER JOIN now.
unmatched rows have NULL dates. WHERE throws them out. no error.
move the filter into ON. the row count is your only clue.