Excel Supreme

Excel track · Exercise 39 of 86 Paid

XLOOKUP: search from the bottom

Return the latest entry for a repeated key without sorting the log first.

Advanced

Activity log with repeat SKUs

Read-only data · screen 1 of 3 · answer in B7

In B7, return the most recent price logged for the SKU in A7, which the log records twice.

AB
1SKUPrice
2TX-10119.99
3TX-10214
4TX-10121.5
5TX-1039.5
6TX-10216.25
7TX-101
8TX-102

Download this grid (.xlsx) Two tabs: the grid you see, and the answer.

B7

What it does

The log is append-only, so the newest price for a SKU is the last row that names it. Search mode -1 walks the key column from the bottom until it finds one. TX-101 sits in rows 2 and 4, so the answer is the 21.5 in row 4.

The fourth and fifth arguments are skipped with empty commas, which puts -1 in the sixth slot. With the default direction the same formula returns 19.99: a real price from a real row, wrong only because it is the older entry.

Other routes reach 21.5 too, but each needs a sorted column or a date to compare against. This argument asks nothing of the sheet beyond the order it already has.

Syntax

=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])

Worked example

On Activity log with repeat SKUs, =XLOOKUP(A7,A2:A6,B2:B6,,0,-1) returns 21.5.

=XLOOKUP(A7,A2:A6,B2:B6,,0,-1)

Common errors

Error codes for XLOOKUP
ErrorWhat it means and how to fix it
#N/AThe key is not in the searched range, which happens when the range points at the price column or stops before the last row.
#VALUE!The key range and the price range are different sizes, so a row in one has no partner in the other.

At work

Price logs, stock movements and status changes where a key is written again later, and the newest row wins.