Skip to content

Guides

How to compare two Excel files or sheets (XLS, XLSX, CSV) and find differences

Find added, removed and changed rows between two versions of a spreadsheet, using formulas, Power Query, Python, SQL or a free online tool.

By Ketan · Updated

“What changed since last week?” It’s one of the most common questions in data work. A supplier sends a new price list. HR exports a new staff list. Two people edit copies of the same spreadsheet. You need to know, row by row, what’s different.

Reconciling two versions of a table is something I do almost every week: before and after a pipeline change, last month’s export against this month’s, a system report against a spreadsheet someone maintains by hand.

Everything here works the same for older .xls workbooks, newer .xlsx files and CSV exports.

The hard part isn’t the tool. It’s being clear about what you’re comparing, so this guide starts there.

Decide how rows are matched

There are two ways to line up two versions of a table:

By position. Row 5 in the old file is compared with row 5 in the new file. This only works if nobody has sorted, inserted or deleted a row. Insert one row near the top and every row below it looks changed.

By a key. Each row has an identifier, like an order number, SKU, employee ID or email, and rows with the same key are compared, wherever they sit. This is almost always what you want, because it can tell three situations apart:

  • Added: the key is only in the new file.
  • Removed: the key is only in the old file.
  • Changed: the key is in both, but some values differ.

If your data has no key column at all, you can still compare whole rows: any row that doesn’t appear in the other file is reported. You just can’t tell an edited row from a deleted one plus a new one.

The quick way: in your browser

The Compare two files tool does key-based and whole-row comparisons on CSV or Excel files. It suggests a key column, shows counts of changed, added and removed rows, and highlights each changed cell with its old and new value. The Excel report it downloads has a sheet for each kind of difference. The files are compared on your computer and not uploaded.

In Excel: formulas

Put both versions in the same workbook, on sheets called Old and New, with the key in column A.

Find rows that were added (in New, not in Old). In an empty column of the New sheet:

=IF(ISNA(MATCH(A2, Old!A:A, 0)), "added", "")

Find rows that were removed. The same formula on the Old sheet, pointing at New!A:A, and labelled “removed”.

Find changed values. In the New sheet, bring back the old value for a column, for example the price in column C:

=XLOOKUP(A2, Old!A:A, Old!C:C, "")

Then compare it with the new value: =IF(C2<>D2, "changed", ""). Repeat for each column you care about. On older Excel versions without XLOOKUP, use =IFERROR(VLOOKUP(A2, Old!A:C, 3, FALSE), "").

Highlight differences by position (only when rows are in the same order): select the range on the New sheet, go to Home → Conditional Formatting → New Rule → Use a formula, enter =A1<>Old!A1, and choose a fill colour.

In Excel: Spreadsheet Compare and Power Query

Microsoft’s Spreadsheet Compare app compares two whole workbooks, including formulas and formatting. It’s only included with certain business editions of Office (Office Professional Plus and Microsoft 365 Apps for enterprise). Search for it in the Start menu to see whether you have it.

Power Query works in every recent version. Load both tables (Data → From Table/Range), then use Home → Merge Queries on the key column. A Left Anti join returns rows that are only in the first table, which gives you removed rows. Swap the order to get added rows. A Full Outer join puts both versions side by side, so you can add a column that compares the values.

In Python (pandas)

import pandas as pd

old = pd.read_csv("price_list_jan.csv", dtype=str)
new = pd.read_csv("price_list_feb.csv", dtype=str)

both = old.merge(new, on="sku", how="outer", suffixes=("_old", "_new"), indicator=True)

added   = both[both["_merge"] == "right_only"]
removed = both[both["_merge"] == "left_only"]

matched = both[both["_merge"] == "both"]
changed = matched[(matched["price_old"] != matched["price_new"]) |
                  (matched["stock_old"] != matched["stock_new"])]

indicator=True adds the _merge column that says where each row came from. For two tables with identical shape and order, old.compare(new) lists cell-level differences directly.

In SQL

With both versions loaded as tables, EXCEPT gives rows in one but not the other:

SELECT * FROM new_prices
EXCEPT
SELECT * FROM old_prices;   -- added or changed rows

To classify every difference by key, use a full outer join:

SELECT COALESCE(n.sku, o.sku) AS sku,
       CASE WHEN o.sku IS NULL THEN 'added'
            WHEN n.sku IS NULL THEN 'removed'
            ELSE 'changed' END AS status,
       o.price AS old_price, n.price AS new_price
FROM old_prices o
FULL OUTER JOIN new_prices n ON n.sku = o.sku
WHERE o.sku IS NULL OR n.sku IS NULL OR o.price <> n.price;

FULL OUTER JOIN works in PostgreSQL, SQL Server, BigQuery, Snowflake and DuckDB. MySQL doesn’t support it; combine a LEFT JOIN and a RIGHT JOIN with UNION instead.

Why too much shows up as “changed”

If almost every row is reported as changed, the data is usually fine, but the formatting differs between the two files:

  • Number formats. 1450 vs 1,450.00, or 0.5 vs 50%.
  • Date formats. 2026-02-01 vs 01/02/2026.
  • Trailing spaces and case. Pune vs Pune, or ASHA@MAIL.COM vs asha@mail.com.
  • Leading zeros lost in one export, but not the other: 02134 vs 2134.

Make both files use the same format before comparing, or use the Ignore extra spaces and Ignore upper/lower case options in the compare tool.

Duplicate keys break key-based comparison

From experience: checking that the key is unique in both files is the first step I take, before any comparison. It takes a minute and prevents the most misleading kind of result: one that looks complete but isn’t.

If the key column has repeats, such as two rows for SKU A100, there’s no single “old” row to compare with. Check first: the Remove duplicates tool with only the key column ticked shows how many repeats there are. Then either clean them up, or choose a combination of columns that is unique.