Adding, averaging, counting, and writing basic IF statements handles one row at a time. Most real spreadsheets require connecting two tables or pulling a filtered slice out of a larger dataset. This guide covers the four functions built for that: XLOOKUP, INDEX/MATCH, FILTER, and QUERY.
Why SUM and IF are not enough
A single-sheet budget is straightforward. Once you have a Products sheet and a separate Orders sheet, and you need to pull each product's name and price into Orders, you need a formula that finds a value in another table and returns data from the same row. That is a lookup.
XLOOKUP: the modern lookup
XLOOKUP takes three core arguments: what to search for, where to search, and what to return.
=XLOOKUP(A2, Products!A:A, Products!B:B)
This takes the value in A2, looks for it in column A of the Products sheet, and returns the matching value from column B.
| A | B | |
|---|---|---|
| 1 | Order ID | Price |
| 2 | SKU-104 | 12.50 |
| 3 | SKU-207 | 8.00 |
XLOOKUP defaults to an exact match, searches in any direction (left-to-right or right-to-left, unlike VLOOKUP), and accepts an optional fourth argument for missing values: =XLOOKUP(A2, Products!A:A, Products!B:B, "Not found").
VLOOKUP and INDEX/MATCH: what you will still encounter
Older spreadsheets, and plenty of newer ones, still use VLOOKUP. It works, but the return column is specified by position number rather than range:
=VLOOKUP(A2, Products!A:B, 2, FALSE)
This finds A2 in the first column of Products!A:B and returns the value 2 columns over. That 2 breaks silently if someone inserts a column. The older alternative, INDEX paired with MATCH, avoids that issue by keeping the lookup and return columns separate:
=INDEX(Products!B:B, MATCH(A2, Products!A:A, 0))
XLOOKUP covers what both VLOOKUP and INDEX/MATCH do with shorter syntax, but it is still worth recognizing all three when editing other people's sheets.
FILTER: pulling out a subset of rows
FILTER returns every row that matches a condition as a live spilling range instead of a single cell.
=FILTER(A2:C20, C2:C20 = "Food")
| A | B | C | |
|---|---|---|---|
| 1 | Expense | Amount | Category |
| 2 | Groceries | 64 | Food |
| 3 | Bus pass | 45 | Transport |
| 4 | Takeout | 22 | Food |
When the source data changes, the filtered output updates automatically. You can pass multiple conditions separated by commas (AND logic): =FILTER(A2:C20, C2:C20="Food", B2:B20>20) returns only Food rows over 20. For OR logic, add boolean expressions with +, such as (C2:C20="Food") + (C2:C20="Transport").
QUERY: SQL-style grouping and sorting
QUERY handles sorting, grouping, and aggregation in a single formula using a compact SQL-like language:
=QUERY(A2:C20, "SELECT C, SUM(B) WHERE C IS NOT NULL GROUP BY C ORDER BY SUM(B) DESC")
That formula groups every expense by category, sums each group, and sorts from highest to lowest, doing the work of a small pivot table in one cell. The syntax takes a little practice, but it replaces long chains of FILTER, UNIQUE, and SUMIF.
Putting it together: a two-sheet lookup project
- Create a
Productssheet: column A = SKU, column B = name, column C = price. - Create an
Orderssheet: column A = SKU ordered, column B = quantity. - In
Orders!C2, pull the price with=XLOOKUP(A2, Products!A:A, Products!C:C). - In
Orders!D2, calculate the line total:=B2*C2. - In a summary cell, total everything with
=SUM(D:D), or isolate one product with=FILTER(A2:D20, A2:A20="SKU-104").
| A | B | C | D | |
|---|---|---|---|---|
| 1 | SKU | Qty | Price | Total |
| 2 | SKU-104 | 3 | 12.50 | 37.50 |
This two-sheet setup is the standard structure for reporting spreadsheets: one sheet stores reference data, and another looks it up and calculates totals.
Where to go next
- Pair
QUERYwith SPARKLINE and conditional formatting. See the conditional formatting guide. - To pull ranges across separate spreadsheet files rather than tabs in the same file, read the IMPORTRANGE reference.
- Read XLOOKUP vs INDEX/MATCH for edge cases where one works better than the other.