Cleaning the Same Dates Every Morning (When Every Query Fixes Raw Data Again)
The Problem
Every query starts the same way: fix the dates. Then the time zones. Then turn the money from text into numbers, and decide what "N/A" means this time. Five analysts do it five slightly different ways. One converts to Eastern, one leaves it in UTC. One treats a blank as zero, one drops the row. Each fix is reasonable. Together they're why two dashboards built from the same data never match. Nobody owns the cleaning, so everybody does it, every morning, forever.
The Principle
Clean it once, at the door. Between raw and everything else, add one layer whose only job is formats: dates, time zones, money, numbers, yes and no, blanks, codes and addresses, each written one standard way. Call it cleaned raw. Most teams call it bronze. Format, not meaning. This layer changes how the data is written, never what it says. No business rules, no joins across systems, no dropped rows: flag the test accounts, don't delete them. Same rows in, same rows out. And name every column in full words, so anyone who opens the table can read it without a lookup. Store dates the same way everywhere, keep timestamps in one time zone, and keep money in whole cents. A thousand tiny decisions disappear, and every query after this one starts from the same place.
3 Steps to Take Action
- 1
Find the cleanup everyone repeats
Pull a month of query logs and look for the same fixes showing up again and again: date parsing, time zone conversion, text to number, blanks to zero. The most-repeated fix goes first.
- 2
Write the format standard on one page
Dates, time zones, money, numbers, yes and no, blanks, codes, addresses: one standard way each, and column names in full words. Get the people who build the data and the people who use it to agree before you build anything.
- 3
Build cleaned raw, then delete the fixes downstream
One cleaned raw table per source, same rows as raw, tested so a new format gets caught before a dashboard sees it. Then take the old cleanup out of the queries, one at a time, and check the numbers still match.
💡 Inspired By
The essay "People and Systems Over Solutions" in The Auction Block, and Brian Cariveau’s talks on data layers.
This is what Analytics Pitfalls & Principles is about: people helping people.
In Practice
A support team ran three call systems. Every report on handle time began with forty lines of the same cleanup: one system logged local time, one logged UTC, one logged seconds as text. Three analysts wrote it three ways, and the weekly numbers were off by as much as an hour depending on whose query ran. They moved the cleanup into one cleaned raw table per system. Same rows as raw, every timestamp in UTC with the original kept beside it, durations as whole seconds. The forty lines came out of every report. The numbers matched the first week, and the next new analyst never had to learn the cleanup at all.
