How Claude Code Handles 'Why Don't These Numbers Match?' Questions
Tracing metric discrepancies across tables and transformations
'Why don't these numbers match?' is the question every data team dreads — and Claude Code, paired with lineage and semantic context, turns it from a day-long manual investigation into a structured debugging session. The agent traces metrics through transformations, compares filters and joins, and surfaces the divergence point automatically.
A stakeholder opens two dashboards, sees different revenue figures, and files a ticket. What follows is hours or days of manual work: tracing metrics through transformations, checking join conditions, comparing filters, and validating business logic across multiple layers. Claude Code, paired with the right context and tooling like Data Workers, turns this from a slog into a traceable, repeatable debugging workflow.
This use case surfaces constantly on Reddit. Data engineers describe spending 20-40% of their time answering 'why don't the numbers match' questions from stakeholders, product managers, and executives. The problem is not that the investigation is technically difficult — it is that it requires navigating multiple systems, holding complex state in your head, and systematically ruling out causes. This is exactly the kind of work that AI agents excel at when given proper context.
The Anatomy of a Number Mismatch
Before diving into how Claude Code handles this, it is worth understanding why numbers mismatch in the first place. Every mismatch falls into one of six categories, and effective debugging means systematically checking each one.
| Category | Example | Frequency |
|---|---|---|
| Definition mismatch | Dashboard A shows gross revenue, Dashboard B shows net revenue | 35% |
| Filter mismatch | One query excludes test accounts, the other does not | 25% |
| Timing mismatch | One report uses data refreshed at 6 AM, the other at midnight | 15% |
| Join mismatch | An inner join drops records that a left join would preserve | 10% |
| Aggregation mismatch | COUNT DISTINCT vs COUNT produces different numbers on duplicate rows | 10% |
| Data quality issue | Source data has nulls, duplicates, or late-arriving records | 5% |
Step 1: Defining the Discrepancy Precisely
The first thing Claude Code does — and the step most humans skip — is define the discrepancy precisely. 'The numbers don't match' is not actionable. Claude Code starts by asking structured questions: What metric? What time period? What are the two specific values? Where are they displayed? When was each last refreshed?
This precision matters because it narrows the search space immediately. If Dashboard A shows $4.2M revenue for Q1 and Dashboard B shows $3.8M, that is a $400K gap. Claude Code can then work backwards: is the gap consistent (suggesting a systematic filter difference) or variable (suggesting a timing or data quality issue)?
Step 2: Tracing the Metric to Its Source
Claude Code uses lineage information to trace each number back to its source table and the transformations applied along the way. In a typical data stack, a dashboard metric might flow through: raw source table, staging model, intermediate transformations, a final reporting table, and then a BI tool's caching and aggregation layer. Each step is a potential point of divergence.
When paired with Data Workers' Lineage Agent, Claude Code can automatically pull the full lineage graph for both metrics and identify where the paths diverge. If both metrics trace back to the same source table but go through different transformation chains, the discrepancy is in the transformations. If they trace back to different source tables entirely, the problem is a definition mismatch.
Step 3: Comparing Transformations Side by Side
Once the divergence point is identified, Claude Code pulls the actual SQL or dbt model definitions for both transformation chains and compares them systematically. It looks for the specific differences that cause number mismatches: different WHERE clauses, different JOIN types, different aggregation methods, different date truncation logic, and different handling of NULL values.
This is where Claude Code's ability to reason about SQL becomes critical. It does not just diff the queries syntactically — it reasons about what the differences mean semantically. A difference of WHERE status != 'cancelled' versus WHERE status = 'completed' might not look significant at first glance, but Claude Code recognizes that orders with status 'pending' or 'processing' would be included in the second query but excluded from the first.
Step 4: Quantifying Each Source of Discrepancy
Claude Code does not just identify possible causes — it quantifies them. For each potential source of discrepancy, it generates a diagnostic query that measures the exact impact. If the issue is a filter difference, it runs a query showing how many records and how much revenue the different filters include or exclude.
- •Filter impact analysis. 'The test account filter in Dashboard A excludes 847 accounts worth $380K in revenue. Dashboard B includes these accounts. This accounts for 95% of the $400K discrepancy.'
- •Join impact analysis. 'The inner join in the reporting model drops 1,204 orders that have no matching customer record. A left join would preserve them, adding $42K to the total.'
- •Timing impact analysis. 'Dashboard A was last refreshed at 06:00 UTC. Dashboard B was refreshed at 00:00 UTC. 2,847 orders were created between midnight and 6 AM, totaling $312K.'
- •Aggregation impact analysis. 'The source table contains 14,302 duplicate order IDs. COUNT returns 14,302 while COUNT DISTINCT returns 13,891 — a difference of 411 records.'
Step 5: Generating the Root Cause Report
After quantifying all sources of discrepancy, Claude Code produces a structured root cause report that explains the mismatch in both technical and business terms. The report includes: the exact discrepancy amount, the ranked list of contributing factors with their individual impact, the specific code or configuration that causes each factor, and a recommended fix.
This report is what transforms a 'why don't these numbers match' ticket from a multi-day investigation into a 30-minute resolution. The data engineer reviews the report, validates the diagnostic queries, and implements the fix — rather than spending days reproducing the investigation from scratch.
Why Context Makes Claude Code Effective at Data Debugging
Claude Code alone can reason about SQL and data transformations. But Claude Code with proper context — schemas, lineage, business definitions, quality signals — is dramatically more effective. This is the layer that Data Workers provides. The 15-agent swarm feeds Claude Code (and any other AI tool in your stack) with the metadata, lineage, and semantic context it needs to debug accurately.
Without context, Claude Code might identify that two queries use different filters but cannot determine which filter is correct. With business context from Data Workers' Catalog Agent, it knows that the governed definition of 'active customers' excludes test accounts — making it immediately clear which dashboard has the bug.
Practical Tips for Data Debugging with Claude Code
- •Provide both queries. Do not just describe the discrepancy — paste the actual SQL or dbt model code for both sources into the conversation.
- •Include schema context. Share the relevant table definitions, especially column types and relationships. Claude Code reasons much better with explicit schema information.
- •Share sample data. A few rows of actual output from each query helps Claude Code identify specific records that appear in one result but not the other.
- •Use Data Workers for lineage. If you do not know which transformations sit between your source and your dashboard, the Lineage Agent can map the full path automatically.
- •Ask for diagnostic queries. Tell Claude Code to generate queries you can run to validate each hypothesis. This keeps you in control while leveraging the agent's analytical reasoning.
The 'why don't these numbers match' question will never go away — but the time it takes to answer it can drop from days to minutes with the right tools and context. Claude Code handles the analytical reasoning. Data Workers provides the context layer. Together, they turn data debugging from a dreaded chore into a structured, repeatable process. Book a demo to see how teams are resolving metric discrepancies faster than ever.
Go from data platform to
agentic platform.
With autonomous AI agents working across your entire data stack — MCP-native, open-source, deployed in minutes.
Book a Demo →Related Resources
- How to Use Claude Code with dbt for Enhanced Data Engineering — Learn how to integrate Claude Code with dbt to enhance your data engineering workflows. Follow ou…
- Using Claude Code for Automated Data Lineage Tracking — Learn how to implement automated data lineage tracking using Claude Code, an essential skill for…
- Claude Code Data Quality Management Tutorial — Learn how to use Claude Code for data quality management in this step-by-step tutorial, focusing…
- Claude Code Data Observability Tutorial — Learn how to use Claude Code for improved data observability in this comprehensive tutorial, enha…
- Using Claude Code for Data Cataloging: A Step-by-Step Guide — Learn how to use Claude Code for data cataloging with our step-by-step guide, enhancing your data…