HomeGoogle DocsSpreadsheetHow to Get Unique Rows Without Considering Timestamp Column in Google Sheets

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

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 K V
Prashanth K V
Your Trusted Google Sheets and Excel Expert Prashanth K V 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

How to Build a Road Trip Fuel Cost Splitter Formula in Google Sheets

Need a fair formula to split fuel costs among travelers on a long road...

Road Trip Fuel Cost Splitter in Google Sheets (Free Template)

When you go on a long road trip with friends, splitting fuel expenses fairly...

Savings Tracker Template in Google Sheets (Free Download)

Managing multiple savings goals can become difficult without a proper system to track your...

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.