Practice problems / Lookup & Reference

Latest order per customer, not the first (XLOOKUP)

Hard Lookup & Reference
Description
Hints 0/4
Solutions 2
–
Test case
1
2
3
Reset
Submit
fx
A
B
C
D
E
F
G
1
2
3
4
5
6
7
8
9
10
Loading interactive spreadsheet...
Preparing grid cells and formula calculation engine
○ Ready Enter formula in highlighted cells, then click Submit.

The problem

Problem statement

Sales asks for the most recent order amount for the customer in E2. The log in A2:C7 is in date order, so the newest row for a customer is the last one that mentions them. Put that amount in the Latest amount cell F2.

A normal lookup returns the first match — you need the last one.

Problem data

Show the sheet as a table (selectable, copyable)
The exercise data, as a table
ABCEF
1 CustomerOrder dateAmountCustomerLatest amount
2 Ada2026-01-05100Ada
3 Ben2026-01-1260
4 Ada2026-01-20150
5 Ada2026-02-02250
6 Ben2026-02-1090
7 Cleo2026-01-1570

Notes

XLOOKUP's sixth argument is the search mode: 0 searches first to last, -1 searches last to first, which turns it into a last-match lookup. The older trick is LOOKUP(2, 1/(keys=target), values): the division turns matches into 1s and misses into #DIV/0!, and LOOKUP finds the last 1. VLOOKUP cannot do this at all without helper columns.

How to approach

Your answer goes in F2. On submit we re-run your formula against 3 different sets of input, so a hardcoded number will fail — the formula has to follow the cells.

  1. Target cell is F2
  2. A default lookup finds the first Ada, which is 100
  3. XLOOKUP has a search mode argument — search backwards
  4. Shape: =XLOOKUP(?, ?, ?, ?, 0, -1)

Official solutions

Show 2 solutions — try it yourself first

Approach 1: XLOOKUP with search mode -1

=XLOOKUP(E2, $A$2:$A$7, $C$2:$C$7, "none", 0, -1)

Searching last to first from the bottom of the log finds Ada's newest row (2026-02-02) and returns 250. Ada appears three times; the other two return 100 and 150.

Approach 2: the LOOKUP(2, 1/(...)) trick

=LOOKUP(2, 1/($A$2:$A$7=E2), $C$2:$C$7)

1/(keys=target) produces 1 for matching rows and #DIV/0! for the rest; LOOKUP ignores errors and returns the value at the last 1. It works in every Excel version, which is why finance models still use it.

Function guide

Related practice

FAQ

How do I get the last matching row instead of the first?

=XLOOKUP(key, keys, values, "", 0, -1) searches last to first. Without XLOOKUP, use =LOOKUP(2, 1/(keys=key), values).

Why does VLOOKUP give me an old order?

VLOOKUP stops at the first match. With multiple rows per customer it returns the oldest one in the log, not the newest.