How to Remove Duplicates in Google Sheets but Keep the Latest, First or Highest Row per Key (2026)

The same customer, student or serial number shows up on several rows: a form submitted twice, an export appended every month, an order history with one row per purchase. You want one row per key, but not just any row: the most recent one, the first one, or the one with the largest amount. Google Sheets’ built-in Remove duplicates always keeps the first row it meets, so the trick is to control what “first” means, or to use a formula that picks the right row for you. This guide shows both, with a worked example, and how to count the duplicates per key before you remove anything.

The example

An Orders tab with a header row and one row per order. Ana has three orders, Bo two:

A: EmailB: NameC: DateD: Total
2ana@x.comAna2026-03-0240
3bo@x.comBo2026-03-0515
4ana@x.comAna Lee2026-04-1125
5cy@x.comCy2026-02-2060
6bo@x.comBo2026-01-3090
7ana@x.comAna Lee2026-03-2870
8dee@x.comDee2026-04-0110

The newest row per email is 4, 3, 5 and 8. The first row per email is 2, 3, 5 and 8. The highest total per email is 7, 6, 5 and 8. Notice that the rows are not in date order, which matters for the shortcuts further down.

Before you start: check that column C holds real dates. =ISNUMBER(C2) should return TRUE. A date imported as text sorts like text (4/11/2026 comes before 4/2/2026), so “newest first” silently picks the wrong row. If it returns FALSE, select the column and use Format › Number › Date, or re-enter the values, before you go on.

Method 1: sort, then Remove duplicates (deletes in place)

  1. Make a copy of the tab (right-click the tab › Duplicate).
  2. Select the whole table, including the header, and choose Data › Sort range › Advanced range sorting options. Tick Data has header row, sort by Date, Z → A. Sort the whole table, not just the date column, or rows will be scrambled.
  3. With the table still selected, choose Data › Data cleanup › Remove duplicates, tick Data has header row, and tick only the Email column under Columns to analyze.
  4. Click Remove duplicates. The tool keeps the first row of each email, which after the sort is the newest.

To keep the highest total instead, sort by Total, Z → A. To keep the first-ever row, sort by date A → Z (or do not sort at all if the sheet is already in the order the rows arrived). The catch: this deletes rows straight away with no preview, and you have to remember to sort every time new rows come in.

Method 2: one formula that keeps the latest row per key (SORTN)

On a new tab, in A2 (put your own headings in row 1):

=SORTN(SORT(FILTER(Orders!A2:D, Orders!A2:A<>""), 3, FALSE), 9^9, 2, 1, TRUE)

Read it from the inside out:

Result for the example: ana@x.com (2026-04-11), bo@x.com (2026-03-05), cy@x.com, dee@x.com, one row each, with all four columns. The result updates as new orders arrive, and the original tab is never changed. When you need a fixed list, copy it and use Edit › Paste special › Values only.

Keep the highest (or lowest) value instead. Sort by the Total column:

=SORTN(SORT(FILTER(Orders!A2:D, Orders!A2:A<>""), 4, FALSE), 9^9, 2, 1, TRUE)

That returns rows 7, 6, 5 and 8 (ana 70, bo 90). Change FALSE to TRUE inside SORT to keep the lowest total per email, or the oldest date.

A key made of several columns. Add more sort columns to SORTN: =SORTN(SORT(FILTER(Orders!A2:D, Orders!A2:A<>""), 3, FALSE), 9^9, 2, 1, TRUE, 2, TRUE) keeps the newest row for each Email + Name pair. In the example that returns two rows for ana@x.com, one for “Ana” and one for “Ana Lee”, which is a sign the names need cleaning, not that the formula is wrong.

The mistake to avoid. It is tempting to write =SORTN(A2:D, 9^9, 2, 1, TRUE, 3, FALSE), sorting by email and then date inside SORTN. That removes nothing: with tie mode 2 every sort column is part of the duplicate check, and no two rows share the same email and date. Sort by the date with SORT first, and give SORTN only the key column(s).

Keep the first row per key

If you want the earliest row as the sheet lists it, the simplest formula leaves out the SORT:

=SORTN(FILTER(Orders!A2:D, Orders!A2:A<>""), 9^9, 2, 1, TRUE)

This returns rows 2, 3, 5 and 8, sorted by email. To keep the rows in their original order instead, filter on a running count:

=FILTER(Orders!A2:D, Orders!A2:A<>"", COUNTIFS(Orders!A2:A, Orders!A2:A, ROW(Orders!A2:A), "<="&ROW(Orders!A2:A))=1)

For each row, COUNTIFS counts the rows from the top down to this one that have the same email; the first copy counts 1. Change "<=" to ">=" to keep the last row in sheet order instead. On large sheets this recalculates slowly, because every row scans the column.

Method 3: flag the row to keep, without moving anything (MAXIFS)

When you want to see the decision next to each row, or delete by hand, add a helper column. In E2 on the Orders tab, fill down:

=IF(A2="", "", C2=MAXIFS($C$2:$C, $A$2:$A, A2))

MAXIFS finds the newest date for this row’s email; the cell says TRUE on the row to keep and FALSE on the older copies. In the example rows 3, 4, 5 and 8 say TRUE. Then either filter column E on FALSE (Data › Create a filter) and delete those rows, or list the keepers elsewhere with =FILTER(Orders!A2:D, Orders!E2:E=TRUE). Swap C for D to flag the highest total. Two things to know: if two rows for the same email share the newest date, both say TRUE, so add a time to the date or decide by hand; and MAXIFS returns 0 when nothing matches, as Google’s help notes.

Count the duplicates per key first

Before deleting, it helps to know how much you are about to remove. One formula lists every key once with its number of rows and newest date:

=QUERY(Orders!A1:D, "select A, count(A), max(C) where A is not null group by A order by count(A) desc label count(A) 'Rows', max(C) 'Latest'", 1)

For the example: ana@x.com 3 rows (latest 2026-04-11), bo@x.com 2, cy@x.com 1, dee@x.com 1. The final 1 tells QUERY there is one header row. Google’s help warns that QUERY gives each column a single data type and treats the minority type as empty, so a few text dates in a date column turn into blanks; one more reason to fix the dates first.

For a count on every row instead, put =COUNTIF($A$2:$A, A2) in a helper column: 3, 2, 3, 1, 2, 3, 1. The number of rows that a dedupe will remove is the total minus the distinct keys: =COUNTA(A2:A)-COUNTUNIQUE(A2:A), 3 in the example. More counting formulas, and why letter case can change this number, are in how to count duplicates.

A shortcut that only works for append-only sheets (XLOOKUP)

If you already have a list of keys and only need the latest values for each, XLOOKUP can search from the bottom up. Its search_mode argument -1 means “search from the last entry to the first”:

=XLOOKUP(F2, Orders!A2:A, Orders!B2:D, "", 0, -1)

That returns the last row for the email in F2, which is the newest only when rows are always added at the bottom in date order, like Google Form responses. In the example it is wrong: Ana’s last row is the March 28 order, not April 11. If you are not sure the sheet is in date order, use Method 2 or 3.

Optional: a script that deletes the older rows in place

For a sheet that keeps growing, such as form responses you want to trim regularly, this Apps Script keeps the newest row per key on the active tab and deletes the rest. It copies the tab to a backup first, compares keys ignoring case and surrounding spaces, keeps the lower row when two dates tie, and stops with an error, deleting nothing, if a key row has a date that is not a real date. Open Extensions › Apps Script, paste it, set the two column numbers, save, then select the tab and run keepLatestPerKey.

// Keep only the newest row per key; delete the older ones. Makes a backup tab first.
// Assumes one header row. KEY_COL and DATE_COL are column numbers (A = 1).
const KEY_COL = 1;   // Email
const DATE_COL = 3;  // Date

function keepLatestPerKey() {
  const ss = SpreadsheetApp.getActive();
  const sheet = ss.getActiveSheet();
  const stamp = Utilities.formatDate(new Date(), ss.getSpreadsheetTimeZone(), 'yyyy-MM-dd HHmm');
  sheet.copyTo(ss).setName(sheet.getName() + ' backup ' + stamp);
  const rows = sheet.getDataRange().getValues().slice(1);
  const toDelete = rowsToDelete_(rows, KEY_COL - 1, DATE_COL - 1);
  toDelete.reverse().forEach(i => sheet.deleteRow(i + 2)); // bottom-up so row numbers stay valid
  ss.toast(toDelete.length + ' older rows deleted');
}

function rowsToDelete_(rows, k, d) {
  const best = new Map(); // key -> index of the newest row so far
  rows.forEach((r, i) => {
    const key = String(r[k]).trim().toLowerCase();
    if (!key) return;
    if (Object.prototype.toString.call(r[d]) !== '[object Date]') throw new Error('Row ' + (i + 2) + ': the date column is not a real date');
    const j = best.get(key);
    if (j === undefined || r[d].getTime() >= rows[j][d].getTime()) best.set(key, i); // tie: the lower row wins
  });
  const keep = new Set(best.values());
  return rows.map((r, i) => i).filter(i => String(rows[i][k]).trim() !== '' && !keep.has(i));
}

It deletes rows one at a time, which is fine for hundreds of rows but slow for many thousands; for big sheets, use the SORTN formula on a new tab. Deleting rows also shifts anything that refers to specific rows, so check formulas and charts that point at this tab afterwards.

Pitfalls

FAQ

Which row does Remove duplicates keep in Google Sheets?

The first row of each group, counting from the top of the selected range. To keep the newest row instead, sort the whole table by the date column, newest first, before you run Data › Data cleanup › Remove duplicates with only the key column ticked.

How do I keep the most recent entry per person with a formula?

Use =SORTN(SORT(FILTER(A2:D, A2:A<>""), 3, FALSE), 9^9, 2, 1, TRUE) where column A holds the key (for example email) and column 3 of the range holds the date. SORT puts the newest row first and SORTN with tie mode 2 keeps one row per key.

Why does SORTN not remove anything when I add the date as a sort column?

With display_ties_mode 2, SORTN treats rows as duplicates only when all of its sort columns match. If the date is a sort column, every email-and-date pair is different, so nothing is removed. Sort by date with SORT first and give SORTN only the key column.

How do I keep the row with the highest value per key?

Same pattern, sorting by the value column instead: =SORTN(SORT(FILTER(A2:D, A2:A<>""), 4, FALSE), 9^9, 2, 1, TRUE). Use TRUE instead of FALSE inside SORT to keep the lowest value.

How do I count how many times each value appears?

=QUERY(A1:D, "select A, count(A) where A is not null group by A order by count(A) desc label count(A) 'Rows'", 1) lists each key once with its number of rows. For a count next to every row, use =COUNTIF($A$2:$A, A2) in a helper column.

Can XLOOKUP return the latest entry?

XLOOKUP with search_mode -1 returns the last match in sheet order, for example =XLOOKUP(F2, A2:A, C2:C, "", 0, -1). That is the newest entry only when rows are added in date order, as with Google Form responses. Otherwise use the SORTN or MAXIFS method.

Rather not maintain formulas? SheetDupes (disclosure: we make it) is a Google Sheets add-on that finds, highlights and removes duplicates from a sidebar. Pick the columns that define a duplicate, preview the matching groups, highlight the extra rows without changing any values, and only then remove or merge them. It copies a backup tab before it removes or merges anything, ignores extra spaces and, optionally, letter case and punctuation. Preview and Highlight are free on any size sheet; there is a 14-day free trial with no credit card, and writes remain free after the trial on sheets with up to 2,000 data rows during launch (through Jan 31, 2027; 500 after that). It only reads and writes the spreadsheet you have open, and your data is not sent to Loomwise. It is live on the Google Workspace Marketplace.
Install free from Google Workspace MarketplaceSee SheetDupes
Want to test it first? Try it on sample data (makes a copy of a 12-row example sheet in your Drive).

Related guides

Function behavior is taken from Google’s Docs Editors Help pages for SORTN, SORT, MAXIFS, QUERY and XLOOKUP. Instructions refer to Google Sheets as it worked on November 18, 2026; menu names can change. Google Sheets is a trademark of Google LLC and this site is not affiliated with Google. Questions or corrections: hello@loomwise.app.