XLOOKUP Latest by Date
Return the most recent value for one selected item from an unsorted history by filtering its dates, finding the maximum eligible date, and retrieving the aligned result.
| XLOOKUP Latest by Date, Formula Review | ||||||||||
| Filter dates by item, take the latest matching date, and return its aligned value from unsorted data. | ||||||||||
| Unsorted price history and filtered dates | Criteria and function review | |||||||||
| Item | Date | Price ($) | Date when selected | Selected item | Belt | |||||
| Bag | Feb 5, 2025 | $42.10 | Missing item example | Scarf | ||||||
| Belt | Mar 12, 2025 | $28.50 | Mar 12, 2025 | |||||||
| Cap | Jul 25, 2025 | $19.90 | (unresolved) | Step | Formula syntax | Result | ||||
| Belt | Jan 10, 2025 | $24.50 | Jan 10, 2025 | MAX all dates | MAX($B$12:$B$21) | Jul 25, 2025 | ||||
| Bag | Jun 2, 2025 | $44.20 | (unresolved) | MAX filtered dates | MAX(($A$12:$A$21=$J$11)*$B$12:$B$21) | Jun 18, 2025 | ||||
| Cap | Apr 8, 2025 | $18.75 | (unresolved) | Latest price | XLOOKUP(MAX($D$12:$D$21),$D$12:$D$21,$C$12:$C$21,"Not found",0) | $31.75 | ||||
| Belt | Jun 18, 2025 | $31.75 | Jun 18, 2025 | Matching rows | COUNTIF($A$12:$A$21,$J$11) | 3 | ||||
| Bag | Jan 22, 2025 | $40.00 | (unresolved) | Missing item | IF(COUNTIF($A$12:$A$21,$J$12)=0,"Not found",XLOOKUP(MAX(($A$12:$A$21=$J$12)*$B$12:$B$21),($A$12:$A$21=$J$12)*$B$12:$B$21,$C$12:$C$21,"Not found",-1)) | Not found | ||||
| Cap | May 15, 2025 | $19.25 | (unresolved) | |||||||
| Bag | Mar 30, 2025 | $43.00 | (unresolved) | |||||||
| Reliability checks | ||||||||||
| Filtered maximum date equals 18-Jun-2025 for Belt | OK | |||||||||
| Latest price returned from the filtered date array equals $31.75 | OK | |||||||||
| Selected item has at least one matching observation | OK | |||||||||
Overview
Return the value attached to the latest dated observation for one selected item, even when the history is unsorted. The example produces a single price after restricting the eligible dates to the chosen product.
When to use it
Use it for the latest product price, exchange rate, forecast version, valuation mark, inventory cost, or contract rate when one item has several dated records and physical row order cannot be trusted.
When not to use it
Use reverse-search XLOOKUP only when rows are reliably ordered oldest to newest. Use MAXIFS plus a separate lookup when displaying the latest date as an explicit audit step matters. Use FILTER and SORT when users need multiple recent observations rather than one result.
Problem
A last-row lookup can return an older record from an unsorted history. Taking MAX across the full date column can also select another product’s date. The latest date must first be limited to rows belonging to the selected item.
Inputs
Input | Location | Sample |
|---|---|---|
Selected item | | Belt |
Source data
The synthetic history in A12:C21 includes ten item, date, and price rows. Its three Belt records are:
Item | Date | Price |
|---|---|---|
Belt | 12-Mar-2025 | $28.50 |
Belt | 10-Jan-2025 | $24.50 |
Belt | 18-Jun-2025 | $31.75 |
Dates must be genuine Excel dates, not text. Item, date, and price ranges must have identical row boundaries. Sorting is unnecessary; duplicate item-date pairs remain ambiguous.
Calculations
- Compare each source item with the selected item.
- Multiply that Boolean array by the date array, preserving matching date serials and converting nonmatches to zero.
- Take MAX to identify the latest matching date.
- Look up that date in the filtered array and return the aligned price.
- Count matching items first so absence produces
Not foundinstead of treating zero as a valid date.
Outputs
For Belt, the workbook returns 18-Jun-2025, $31.75, and 3 matching observations. The result is one currency value; the separate date and count make the selected population visible. A missing item returns Not found.
Formula map
=IF(COUNTIF($A$12:$A$21,$J$11)=0,"Not found",XLOOKUP(MAX(($A$12:$A$21=$J$11)*$B$12:$B$21),($A$12:$A$21=$J$11)*$B$12:$B$21,$C$12:$C$21,"Not found",-1))
The absolute source ranges and criterion cell keep the calculation stable when copied. The two identical Boolean-date arrays derive and then locate the eligible maximum. Search mode -1 allows exact or next-smaller matching; here MAX comes from that same array, so an exact date is present whenever the item exists.
Model checks
The example workbook confirms that the filtered maximum equals 18-Jun-2025, the returned price equals $31.75, and the selected item has at least one observation. Each supplied check returns OK.
Edge cases
- One observation returns that row’s value.
- No matching item returns
Not foundbecause COUNTIF runs before the lookup. - Duplicate rows on the latest date are ambiguous; XLOOKUP returns the first eligible price.
- Text dates do not behave like date serials and can invalidate MAX.
- A blank criterion may match blank item cells inside the bounded range.
- Source errors propagate; the formula does not suppress them.
Common errors
- Using the last physical row: an older observation may be returned. Calculate the filtered maximum date.
- Taking MAX before filtering: another item’s date becomes the key. Apply the item comparison inside MAX.
- Misaligning arrays: the returned price can come from the wrong row. Keep every range on rows 12:21.
- Skipping the missing-item guard: an all-zero filtered array is treated as a lookup target. Test the item count first.
Example
Belt’s three dates are 10-Jan, 12-Mar, and 18-Jun-2025. After other products’ dates become zero, MAX returns 18-Jun-2025. That date aligns with $31.75, which XLOOKUP returns. The table-wide maximum is 25-Jul-2025 for Cap, confirming why the item filter is necessary.
Example workbook
Edit the cream item criterion in Combined Example!J11 or the history in A12:C21. The visible helper in column D, latest date, price, count, formula, and three checks update. Formula Review also demonstrates missing item Scarf.
Key takeaway
Filter the date array before taking its maximum; “latest” must be defined within the selected item’s records, not by row position or the entire history.