In Google Sheets, you might want to extract unique rows from a dataset while ignoring a timestamp column. That’s not something the UNIQUE function is designed to handle directly — especially if you still want to keep the earliest or latest timestamp associated with each unique row.
Thankfully, there’s a neat solution using the SORTN function.
Why Not Just Use UNIQUE?
You might think, “Why not just skip the timestamp column and apply UNIQUE to the rest?”
That works — but you lose the timestamp completely.
What if you want to keep the first time a row appeared? Or maybe the most recent? That’s where SORTN shines.
Why Timestamps Break Deduplication (e.g., in Form Submissions)
If you’re collecting responses using a Google Form, every submission gets a timestamp. In the connected Sheet, it usually appears as the first column.
Now let’s say a user submits the same form multiple times with identical data. Your sheet will have duplicate rows, but with different timestamps.
Here’s the challenge:
You want only one copy of each record — and you’d like to keep the earliest or latest timestamp for each.
Let’s solve that.
Sample Data
Imagine the following dataset in range A1:D:
| Timestamp | Name | Product | Quantity |
|---|---|---|---|
| 2025-07-31 09:10:00 | Ananya | Apples | 3 |
| 2025-07-31 09:11:00 | Ananya | Bananas | 3 |
| 2025-07-31 09:15:00 | Ananya | Bananas | 3 |
| 2025-07-31 10:00:00 | Clara | Bananas | 5 |
| 2025-07-31 10:10:00 | Ananya | Apples | 3 |
| 2025-07-31 10:45:00 | Ananya | Apples | 3 |
| 2025-07-31 15:00:00 | Clara | Bananas | 5 |
Now, if you apply =UNIQUE(B2:D) ignoring the timestamp, you’ll get:
| Name | Product | Quantity |
|---|---|---|
| Ananya | Apples | 3 |
| Ananya | Bananas | 3 |
| Clara | Bananas | 5 |
That’s fine — but again, the timestamp is lost.
Let’s now bring in SORTN to retain either the earliest or latest timestamp for each row.
Get Unique Rows and Keep the Earliest Timestamp
To retain the earliest instance of each row, sort the data ascending by timestamp, then apply SORTN.
Here’s the formula:
=SORTN(SORT(A2:D), 9^9, 2, 2, TRUE, 3, TRUE, 4, TRUE)
What This Does:
Let’s break it down:
SORT(A2:D)– This sorts your data by the Timestamp column (the first column) in ascending order, so the earliest entries come first.SORTN(..., 9^9, 2, ...)– This is where the magic happens:9^9is just a very large number — it tells Google Sheets to return all rows after removing duplicates.2is the tie-breaker mode, which removes duplicate rows based on the columns we specify next.2, TRUE, 3, TRUE, 4, TRUE– These are the column numbers (Name = col 2, Product = col 3, Quantity = col 4) and their sort order (all ascending). These are the columns we’re checking for duplicates.
So, this formula:
- First sorts the data by timestamp,
- Then removes rows that are duplicates based on Name, Product, and Quantity, and
- Returns only the first instance of each — i.e., the row with the earliest timestamp.
Result:
| Timestamp | Name | Product | Quantity |
|---|---|---|---|
| 2025-07-31 09:10:00 | Ananya | Apples | 3 |
| 2025-07-31 09:11:00 | Ananya | Bananas | 3 |
| 2025-07-31 10:00:00 | Clara | Bananas | 5 |
Get Unique Rows and Keep the Latest Timestamp
Just flip the sort order to descending using SORT(A2:D, 1, FALSE):
=SORTN(SORT(A2:D, 1, FALSE), 9^9, 2, 2, TRUE, 3, TRUE, 4, TRUE)
Result:
| Timestamp | Name | Product | Quantity |
|---|---|---|---|
| 2025-07-31 10:45:00 | Ananya | Apples | 3 |
| 2025-07-31 09:15:00 | Ananya | Bananas | 3 |
| 2025-07-31 15:00:00 | Clara | Bananas | 5 |
This version keeps only the latest timestamp per unique combination of Name + Product + Quantity.
Using QUERY to Filter Duplicates by Timestamp
If you prefer not to use the SORT + SORTN combo, there’s a simpler — and more readable — way using the QUERY function in Google Sheets.
By grouping your data and using MIN() or MAX() on the timestamp column, you can easily pull out either the earliest or latest version of each row — while still ignoring the timestamp column when checking for duplicates.
For Earliest Unique Records (Ignoring Timestamp)
This formula will group the data by the Name, Product, and Quantity columns, and return the earliest timestamp for each unique combination:
=QUERY(A1:D, "SELECT MIN(A), B, C, D WHERE A IS NOT NULL GROUP BY B, C, D", 1)
This works great if you’re collecting responses via forms or logs and want to retain when something first occurred.
For Latest Unique Records (Ignoring Timestamp)
To return the most recent timestamp per unique entry, just swap MIN(A) with MAX(A):
=QUERY(A1:D, "SELECT MAX(A), B, C, D WHERE A IS NOT NULL GROUP BY B, C, D", 1)
Use this when you care about the latest update or submission for each person/product combo.
Note
These formulas assume that your timestamp is in column A, and the rest of the data is in columns B to D.
Conclusion
When working with form submissions or log data that include timestamps, you’ll often want to remove duplicates while still keeping either the earliest or latest version of each record.
While the UNIQUE function helps filter out duplicates, it doesn’t let you retain timestamps — which are often critical.
The SORTN + SORT combo gives you precise control and flexibility, especially if you want to deduplicate while preserving the original rows.
Alternatively, the QUERY function offers a more compact solution using MIN() or MAX() to grab the first or last timestamp for each group — perfect for clean summaries or reports.
Both options work well — choose the one that best fits your workflow.
Resources
- Removing Duplicates In Google Sheets: Built-In Tool & Formulas
- Get the Latest Non-Blank Value by Date in Google Sheets
- How to Apply UNIQUE by Specific Columns in Google Sheets
- Find Top 10 Unique Names by Score in Google Sheets
- UNIQUE Function in Visible Rows in Google Sheets
- Filter Items Unique to Groups in Google Sheets
- Retrieve the Earliest or Latest Entry Per Category in Google Sheets
- Combine Rows and Keep Latest Values in Google Sheets





















