Sub topic 1
What a lookup does
A lookup connects two pieces of data by using a shared value called a key. The formula searches for the key in one column, finds the matching row, and returns related data from that row.
For example, a product table might contain these columns:
| Product ID | Product name | Price |
|---|---|---|
| P-101 | Keyboard | 45 |
| P-102 | Monitor | 220 |
| P-103 | Mouse | 25 |
If another part of your sheet contains P-102, a lookup can find that ID and return Monitor or 220. The product ID is the key. The column containing product IDs is the lookup column. The column containing the requested information is the result column.
Prerequisites
You should know how to enter formulas in Google Sheets and how to read cell and range references such as A2:C100. This chapter also assumes that you understand that a range can contain several rows and columns.
The lookup model
A lookup has three important parts:
- Search key: The value to find, such as
P-102. - Lookup range: The column or row where Sheets searches for that value.
- Result range or column: The data to return from the matching row.
The key must identify the intended record. If two rows use the same key, the lookup may return only one of them. The result depends on the function's matching and search settings.
Consider this order table:
| Order ID | Customer | Status |
|---|---|---|
| O-301 | Amina | Shipped |
| O-302 | Luis | Processing |
| O-303 | Mei | Delivered |
If cell E2 contains O-302, the lookup searches the Order ID column. After finding the row for O-302, it returns Processing from that same row.
Search key: O-302
Lookup column: Order ID
Matching row: O-302 | Luis | Processing
Returned value: ProcessingThe lookup does not search every cell for a general similarity. It compares the search key with values in the selected lookup area. Then it uses the position of the matching row to select the result.
Exact identity matters
For record retrieval, the key usually needs an exact match. P-102 should match P-102, not P-1020 or another nearby value. A lookup can fail when the visible values look identical but differ internally. For example, P-102 with a trailing space is different from P-102 without that space.
The data type also matters. The number 102 and the text "102" can behave differently, even though they display similarly. A lookup may return #N/A, which means that no matching value was found.
A lookup also assumes that related values stay on the same row. If you sort only the result column instead of the complete table, the rows no longer represent the original records. A formula can still return a value, but it may return the wrong value for the key.
When lookups are useful
Use a lookup when one table contains identifiers and another part of the workbook needs related details. Common examples include:
- Finding a product price from a product ID.
- Adding a customer's region to an orders table.
- Returning an employee's department from an employee number.
- Matching an invoice number to a payment status.
The key should be stable and meaningful within the data set. Names are often poor keys because two people can share a name. An assigned customer ID or order ID is usually safer.
The lookup concept is independent of the particular function. VLOOKUP and XLOOKUP both use a key to locate a row and return related data. Their syntax and options differ, so choose the function based on the table layout and matching behavior you need.
Exercise
In a table with columns Student ID, Name, and Grade, what are the search key, lookup column, and possible result when the formula searches for S-204?
Show answer
The search key is S-204. The lookup column is Student ID. A possible result is the student's name or grade from the row containing S-204.