How to compare two CSV files and see which rows were added, removed or changed
Updated
Comparing last month's export with this month's is a common job: new customers, cancelled orders, changed prices. Comparing line by line only works if both files are sorted the same way; matching rows by a key is far more reliable.
Pick a key that identifies each row
A good key is stable and unique: an order number, SKU, customer ID or email address. With a key, rows can be in any order and still be matched. Without one, you can only check whether whole rows are identical.
In Excel or Google Sheets
- Put both files in the same workbook, on two sheets (Old and New).
- In the New sheet, add a column with =COUNTIF(Old!A:A, A2)=0 (A = the key column). TRUE means the row is new.
- Do the same in the Old sheet against New to find removed rows.
- For changed rows, look up each key's values in the other sheet (XLOOKUP in Excel, VLOOKUP or XLOOKUP in Google Sheets) and compare them with a formula such as =B2<>XLOOKUP(A2, Old!A:A, Old!B:B).
This works, but it gets slow and error-prone with many columns, because every column needs its own comparison.
The private way: in BenchCove
Free, no sign-up. Uses the File & Data Workbench. Nothing is uploaded.
- Open Compare in the File & Data Workbench and load the original and the new version (CSV or Excel). Both stay in your browser.
- Match rows by key columns (BenchCove suggests likely keys such as an ID or email) or by identical rows.
- See the counts of added, removed, changed and unchanged rows, and which columns changed most.
- Filter the differences, see the old value for each changed cell, and export the result as CSV.
Questions
Do the files need to be sorted?
Not when you match by a key column: rows are found by their key wherever they are. Only line-by-line comparisons need identical sorting.
What if a key appears twice in one file?
Then the key isn't unique and matches can be ambiguous. Remove duplicates on that key first, or combine two columns into a key.
Can I compare an Excel file with a CSV?
Yes. BenchCove reads .xlsx/.xlsm and CSV files, so the two versions don't need to be the same format.