Deduplicate Re-Sent Azure Usage Records Before Computing Billing Totals
Last updated: November 29, 2026
Quick Overview
Azure usage ingestion sometimes re-sends corrected records for the same resource, meter and day; write SQL that keeps only the latest version of each record, attaches tenant names from a subscriptions table, and totals cost per tenant per month.
Microsoft
November 29, 20260
0
0 solved
Azure usage ingestion sometimes re-sends corrected records for the same resource, meter and day; write SQL that keeps only the latest version of each record, attaches tenant names from a subscriptions table, and totals cost per tenant per month.
A phone screen SQL question in the style of Microsoft's commerce and billing data teams, where late and corrected usage records are routine. The interviewer checks that you pick the right deduplication key, use ROW_NUMBER with a deterministic order, and do not lose records whose subscription is missing from the dimension table.
What the Interviewer Expects
- Identify the natural key: resource, meter and usage date
- Use ROW_NUMBER partitioned by the key, ordered by ingestion time descending
- Add a tiebreaker so the result is deterministic
- LEFT JOIN to subscriptions and label unmatched rows
- Aggregate only after deduplication
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you make this incremental so each day only reprocesses affected keys?
- What if corrections arrive as negative adjustment rows instead of replacements?
- How would you alert when the share of unmapped subscriptions spikes?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
usage_records(record_id, subscription_id, resource_id, meter_id, usage_date, cost, ingested_at). A corrected record for the same resource, meter and usage date replaces the earlier one; it does not ...
Approach
Rank versions within each natural key by ingested_at descending and keep rank 1. ROW_NUMBER rather than RANK, because two versions ingested at the same instant must still yield exactly one row; ...