Extract the Last Entry of Each Item by Date in Google Sheets

You don’t need to use QUERY or FILTER to extract the last entry of each item by date in Google Sheets. Instead, you can use a simple combination of SORT and SORTN.

The SORT function is unnecessary if your data is already sorted by the item column and then by the date column. However, for flexibility, we will include it. This formula extracts the latest records from each group based on the date entries.

Where Is This Useful?

Extracting the last entry of each item by date in Google Sheets is useful in various real-life scenarios, such as:

  • Tracking the last recorded stock update for each product.
  • Finding the latest PO (purchase order) for each customer.
  • Extracting the most recent payment or invoice details.
  • Tracking the most recent leave request per employee/student.
  • Extracting the most recent status change for ongoing projects.

Generic Formula

=SORTN(SORT(range, key_col, TRUE, dt_col, FALSE), 9^9, 2, key_col, TRUE)

Where:

  • range – The data range containing the records.
  • key_col – The column number determining the grouping (e.g., product name column number, employee name column number).
  • dt_col – The column number containing the date entries.

Example 1: Extracting the Last Leave Request for Each Employee

Consider the following employee leave data:

Sample data for extracting the last leave request for each employee in Google Sheets

To extract the last leave request record for each employee:

  • key_col is column A (Employee Name).
  • dt_col is column E (Leave Request Date).

Formula:

=SORTN(SORT(A2:E, 1, TRUE, 5, FALSE), 9^9, 2, 1, TRUE)

Output:

EmployeeLeave TypeStart DateEnd DateRequest Date
AaronVacation1-Mar-20245-Mar-202420-Feb-2024
GayatriVacation11-Mar-202415-Mar-20249-Mar-2024

How This Works:

  • SORT(A2:E, 1, TRUE, 5, FALSE): Sorts data by employee name (ascending) and then by request date (descending).
  • This ensures that each employee’s latest leave request appears first in their group.
  • SORTN(..., 9^9, 2, 1, TRUE): Removes duplicate rows based on employee names, keeping only the latest record per employee.

Example 2: Extracting the Last Stock Update per Product

Here is sample data for tracking the last recorded stock update for each product:

Sample data for extracting the last stock update per product in Google Sheets

To extract the last entry of each Product by date:

=SORTN(SORT(A2:D, 2, TRUE, 4, FALSE), 9^9, 2, 2, TRUE)

Output:

CategoryProductStock QtyUpdate Date
ElectronicsLaptop1010-Feb-2025
AccessoriesMouse407-Feb-2025

To extract the last updated date by Category:

=SORTN(SORT(A2:D, 1, TRUE, 4, FALSE), 9^9, 2, 1, TRUE)

Output:

CategoryProductStock QtyUpdate Date
AccessoriesMouse407-Feb-2025
ElectronicsLaptop1010-Feb-2025
GamingLaptop125-Feb-2025

To extract the last updated date by Category and then by Product:

=SORTN(SORT(A2:D, 1, TRUE, 2, TRUE, 4, FALSE), 9^9, 2, 1, TRUE, 2, TRUE)

Output:

CategoryProductStock QtyUpdate Date
AccessoriesMouse407-Feb-2025
ElectronicsLaptop1010-Feb-2025
GamingLaptop125-Feb-2025
GamingMouse453-Feb-2025

Conclusion

This tutorial demonstrated how to extract the last entry of each item by date in Google Sheets using SORT and SORTN. These formulas help efficiently retrieve the most recent records in various scenarios.

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Top N Products and Top N Sellers in Google Sheets (Top N of Top N)

If you’ve ever wanted to compare which sellers contribute the most to your top-selling...

Use XLOOKUP in a Structured Table in Google Sheets (Single and Multiple Conditions)

This tutorial is for users who want to apply XLOOKUP inside a structured table...

Reset SCAN by Another Column in Google Sheets and Excel

Resetting SCAN function results based on values in another column is a topic of...

How to Get the Fastest Time for Each Person in Google Sheets

Whether you’re tracking race results, event times, or any other timed activities, finding the...

More like this

Top N Products and Top N Sellers in Google Sheets (Top N of Top N)

If you’ve ever wanted to compare which sellers contribute the most to your top-selling...

Use XLOOKUP in a Structured Table in Google Sheets (Single and Multiple Conditions)

This tutorial is for users who want to apply XLOOKUP inside a structured table...

How to Get the Fastest Time for Each Person in Google Sheets

Whether you’re tracking race results, event times, or any other timed activities, finding the...

3 COMMENTS

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.