Compare Two Files by Key
Operator: Abdulla Al Fahad. How tools are built and checked
Two exports of the same list rarely line up row for row. A supplier sends a new price sheet in a different order, a CRM export gains a few contacts and loses others, a warehouse count comes back with SKUs in lower case. Compare Two Files by Key pairs the rows by a column you pick, such as an order number, SKU or email address, and then tells you, key by key, whether the row exists only in file A, only in file B, exists in both with different values, or exists in both unchanged.
For a changed row you see which cells moved and from what to what, written as "Unit price: 12 -> 12.75". Either file can be a CSV or an Excel workbook, so you can check last month's .xlsx against this month's .csv without converting anything first.
Key features
- Matches rows on a key column you choose separately for each file
- Picks a column named id, sku, code or email as the key when one exists
- Reports only_in_a, only_in_b, changed and same for every key
- Lists each changed cell with its old and new value
- Compares only the columns whose names appear in both files, with a checkbox for each
- Optional trimming and case-folding of keys, both on by default
- Counts repeated keys in each file and shows up to ten of them
- Reads CSV, XLSX and XLS, in any combination
Each input can be .csv, .xlsx or .xls. From a workbook only the first sheet is read, and its first non-empty row is taken as the header row. Excel numbers arrive as the value the cell stores, not as it is displayed: a price formatted to show 12.00 is read as 12. Cells with a date format are read as the date text Excel would show. Formulas are read as their last saved result.
CSV files are read as UTF-8, or as UTF-16 when the file starts with a UTF-16 byte-order mark. Fields may be quoted, and a quoted field can hold commas and line breaks. Only commas are treated as separators; a semicolon-delimited file shows up as one wide column, and you will see that straight away in the key column list.
The download is a CSV with three columns: key, status (only_in_a, only_in_b, changed or same) and changed_columns. The key is written as it appears in file A, or in file B for keys that exist only there. The file starts with a UTF-8 byte-order mark so that Excel shows accented characters correctly when you double-click it. Any field that begins with =, +, @, a tab or a carriage return is written with a leading apostrophe, so a key such as =SUM(A1) opens as text instead of running as a formula; values starting with a minus sign are left alone so negative numbers stay intact.
How it works
When you choose a file, it is parsed straight away so the key and column lists can be filled in. The tool then builds a lookup of each file's rows by key. With both key options on, " kb-104 " and "KB-104" become the same key. A row whose key is blank after this step is skipped and counted. If a key turns up a second time in the same file, the later row is skipped and counted as a duplicate, so every key points at the first row that carried it.
Columns are paired by header name, trimmed and compared without regard to case, so "Unit price" in one file pairs with "unit price " in the other. A column that exists in only one file is never compared, because there is nothing to compare it with. For each key present in both files, the tool walks the ticked columns and compares the two cells as text after trimming spaces. One exception: when both cells are plain numbers, such as 18.50 and 18.5, they are compared by value, so a CSV that writes two decimals does not flag every price in an Excel file that stores none.
The results list follows file A's row order, followed by the keys found only in file B in file B's order.
Common use cases
- Checking a supplier's new price list against the old one to see which SKUs went up, which were dropped and which are new.
- Matching an order export from a web shop against the warehouse dispatch file to find orders that never shipped.
- Comparing a mailing list before and after a cleanup to confirm which email addresses were removed.
- Checking that a data migration copied every customer record and kept their fields intact.
- Reconciling a staff list from HR with the accounts list from IT, keyed on employee number.
How to use this tool
- Choose file A, usually the older or reference export.
- Choose file B, the file you want to check against it.
- Check the key column for each file. Change it if the guess is wrong, for example when the header is "Order No" rather than id.
- Untick any shared column you do not care about, such as a last-modified timestamp that differs on every row.
- Leave both key options on unless case or spacing in the key really matters.
- Press Compare and read the four counts and the notes about repeated or blank keys.
- Tick "Include unchanged rows" if you want every key in the report, then download reconcile-report.csv.
Example
File A is supplier-prices-march.xlsx; file B is supplier-prices-april.csv
File A (first sheet)
SKU | Description | Unit price | Pack size
KB-104 | Keyboard, wired | 18.50 | 1
MS-220 | Mouse, wireless | 12.00 | 1
CB-010 | USB-C cable 1 m | 4.20 | 5
HD-330 | Headset | 39.00 | 1
File B
sku,description,unit price,pack size,lead time
kb-104,"Keyboard, wired",18.5,1,3 days
MS-220,"Mouse, wireless",12.75,1,5 days
CB-010,USB-C cable 1 m,4.20,10,2 days
CB-010,USB-C cable 1 m,4.10,10,2 days
DS-500,Docking station,89.00,1,7 daysreconcile-report.csv with the default settings (unchanged rows left out)
key,status,changed_columns
MS-220,changed,Unit price: 12 -> 12.75
CB-010,changed,Pack size: 5 -> 10
HD-330,only_in_a,
DS-500,only_in_b,
Summary: Only in A 1, Only in B 1, Changed 2, Same 1
File B has 1 row with a repeated key (CB-010); the first one was used.Tips for best results
- Pick a key that is unique in both files. If the counts show many repeated keys, you probably need a different column, such as an invoice number instead of a customer name.
- When the two systems name the key differently, for example "Email" in one and "contact_email" in the other, just pick each one separately. Only the compared columns need matching names.
- Untick columns that always differ, such as export timestamps, or every key will show as changed.
- If a column you expected is missing from the checkbox list, its header is spelled differently in the two files. Rename one header and pick the file again.
- Swap A and B if you want the keys in the report to follow the other file's spelling and row order.
Common pitfalls
Leading zeros are the most common trap. If one file stores 00412 as text and the other stored it as the number 412 because it passed through Excel, the keys will not match and the row appears twice, once as only_in_a and once as only_in_b. Fix the key column in the source before comparing.
Number matching only covers plain numbers. "$12.00" and "12" are different text, and so are "1,200" and "1200", so a currency symbol or a thousands separator in one file will show up as a change.
Dates are compared as text. 2026-04-01 in a CSV and 01/04/2026 shown by Excel are reported as changed even though they are the same day.
Only the first occurrence of a repeated key is compared. If the second row is the one that matters, remove the first or sort the file before comparing.
The results table on the page stops at the first 500 rows. A note under it says how many rows there are in total, and reconcile-report.csv always contains every row, so filter large comparisons in the download rather than scrolling the page.
Common errors and how to fix them
- "This looks like a binary file, not a text CSV. Choose a CSV file."
- The file has a .csv name but contains binary data, often an Excel workbook that was renamed. Give it its real .xlsx extension, or export it as CSV from the program that made it.
- Every row shows as only_in_a or only_in_b and nothing matches.
- The key columns do not hold the same values. Check that you picked the right column on each side, and look for prefixes ("INV-1001" against "1001") or lost leading zeros.
- Every matched key shows as changed.
- A ticked column differs on every row, such as a timestamp or a row number. Untick it and compare again.
- The file is refused for its size or row count.
- Each file is limited to 25 MB and 100,000 data rows. Split the file by a column such as year or region and compare the parts.
Best practices
- Keep file A as the reference, such as last month's export, so only_in_b reads naturally as "new" and only_in_a as "gone".
- Read the duplicate and blank-key notes before trusting the counts; they explain rows that seem to be missing.
- Download with unchanged rows included when you need a full audit trail that lists every key.
- Spot-check one or two changed keys in the original files before acting on the report.
How this differs from Diff CSV
The site's Diff CSV tool compares whole rows. It joins the values of the shared columns into one string per row and checks whether that exact string exists in the other file. A row with one changed price therefore appears twice in its output: the old version as only_left and the new version as only_right, and you have to spot which cell differs yourself. It accepts CSV only.
Compare Two Files by Key first pairs the rows by a key, so a changed price shows up once, as changed, with the column name and both values. Rows are matched even when the files are sorted differently or the key differs in case or spacing. It also reads .xlsx and .xls directly. Use Diff CSV when your data has no key column and you only need to know which exact rows are new or gone; use this tool when each row has an identifier.
Limits that change the result
It compares one key column, not a combination. If a row is only unique by date and store together, add a column that joins the two in each file first. It does not match keys approximately, so "Jon Smith" and "John Smith" are different keys. It reads only the first sheet of a workbook, and it does not report columns that exist in only one file, beyond leaving them out of the checkbox list.
Frequently asked questions
Can file A be Excel and file B a CSV?
Yes. Each side is read on its own, so any mix of .csv, .xlsx and .xls works. Plain numbers are compared by value, so 18.5 stored in Excel and 18.50 written in a CSV count as equal.
What happens when the same key appears twice in one file?
The first row with that key is used and the later ones are skipped. The summary says how many rows were skipped in each file and lists up to ten of the repeated keys so you can look them up.
Do the key columns need the same header in both files?
No. You pick the key column for A and for B separately. The columns whose values are compared, on the other hand, are paired by header name.
Why do I only see 500 rows in the results table?
The page shows the first 500 result rows to keep the table quick to scroll. The counts above it cover every key, and the downloaded reconcile-report.csv includes every row, plus the unchanged ones if you tick that option.
What happens to a large Excel file while it is being read?
The workbook's bytes are loaded with File.arrayBuffer and handed to SheetJS, which unpacks the first sheet into memory inside this tab. Only the cells that hold a value are kept, as rows of text, and those rows stay in the page's state until you remove the file or close the tab. Nothing is saved to browser storage, so reopening the page starts empty.