How to Get Unique Rows Without Considering Timestamp Column in Google Sheets

Published on

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:

TimestampNameProductQuantity
2025-07-31 09:10:00AnanyaApples3
2025-07-31 09:11:00AnanyaBananas3
2025-07-31 09:15:00AnanyaBananas3
2025-07-31 10:00:00ClaraBananas5
2025-07-31 10:10:00AnanyaApples3
2025-07-31 10:45:00AnanyaApples3
2025-07-31 15:00:00ClaraBananas5

Now, if you apply =UNIQUE(B2:D) ignoring the timestamp, you’ll get:

NameProductQuantity
AnanyaApples3
AnanyaBananas3
ClaraBananas5

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^9 is just a very large number — it tells Google Sheets to return all rows after removing duplicates.
    • 2 is 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:

TimestampNameProductQuantity
2025-07-31 09:10:00AnanyaApples3
2025-07-31 09:11:00AnanyaBananas3
2025-07-31 10:00:00ClaraBananas5

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:

TimestampNameProductQuantity
2025-07-31 10:45:00AnanyaApples3
2025-07-31 09:15:00AnanyaBananas3
2025-07-31 15:00:00ClaraBananas5

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

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Expert Prashanth KV is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Top Discussions

More like this

Pivot Table Formatting, Output & Special Behavior in Google Sheets

Pivot Tables in Google Sheets are powerful—but they can get tricky once you move...

Pivot Table Calculations & Advanced Metrics in Google Sheets

When it comes to built-in tools for data analysis and visualization in Google Sheets,...

Google Sheets Pivot Table Tutorial: Basics, Setup, and Date Grouping

The easiest way to summarize, analyze, and report data in Google Sheets is by...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.