Find Any Product Price in Google Sheets with XLOOKUP
Enter a product ID and return its price with an exact match.
Download practice data · CSVStart the exerciseWatch the tutorial
Watch on YouTube · ShortTry it yourself
Import at A1. Type P-103 in D2, then put the formula in E2. Expect 249. Try an unknown ID to see Not found. Duplicate IDs return the first match.
=XLOOKUP(D2,A2:A6,B2:B6,"Not found",0)Detailed steps
- 1. Keep the lookup table simple
In this fictional catalog, column A contains product IDs and column B contains prices. The data runs from row two to row six. Keep each product ID unique.
- 2. Add an input and output
Type the product ID you want in D two. Here it is P one oh three. Click E two for the price result. Keeping the input separate makes the formula reusable.
- 3. Enter XLOOKUP
Enter XLOOKUP with D two as the search key. Next use A two through A six for the IDs, and B two through B six for prices. Add Not found in quotation marks, then zero for an exact match.
- 4. Read the matching result
Press Enter. The result is two hundred forty nine dollars, from the row for P one oh three. The lookup and result ranges must have matching lengths. The source table stays unchanged.
- Two checks before using it
A missing ID returns our Not found message. Duplicate IDs can return the first match, so check your catalog. Also watch extra spaces in imported IDs. Which lookup should we build next: prices, stock, or customer details?
Use the product code as the key
The lookup range contains identifiers and the return range contains prices at the same row positions. Exact matching avoids silently substituting a nearby product. The not-found label separates an unknown code from a legitimate zero price. Keep units and currency visible: the formula returns the stored number and does not convert currencies.
When the result looks wrong
Duplicate product codes make the first matching row win. If a valid code is not found, compare trailing spaces and text versus numeric codes. Lock source ranges with dollar signs before copying the lookup into several order rows; otherwise they can slide away from the price list.
A check you can repeat
P-103 returns 249 USD. P-999 returns Not found rather than a price. Add a second P-103 with a different price to a separate test copy: the first match still wins, so duplicate keys require a data decision.
Preview the input data
| Product ID | Price (USD) |
|---|---|
| P-101 | 49 |
| P-102 | 25 |
| P-103 | 249 |
| P-104 | 35 |
| P-105 | 79 |
Need help importing, choosing separators or setting the locale? How to use the practice files.