← Guides

Guide 2

Lookups and Filters: The Next Step

Go past static SUM and IF formulas. Use XLOOKUP, INDEX/MATCH, FILTER, and QUERY to pull and slice data across sheets.

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.

B2fx=XLOOKUP(A2, Products!A:A, Products!B:B)
AB
1Order IDPrice
2SKU-10412.50
3SKU-2078.00
B2 looks up SKU-104 in the Products sheet and returns its price.

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")
ABC
1ExpenseAmountCategory
2Groceries64Food
3Bus pass45Transport
4Takeout22Food
=FILTER(A2:C4, C2:C4="Food") returns only the Food rows (rows 2 and 4).

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

  1. Create a Products sheet: column A = SKU, column B = name, column C = price.
  2. Create an Orders sheet: column A = SKU ordered, column B = quantity.
  3. In Orders!C2, pull the price with =XLOOKUP(A2, Products!A:A, Products!C:C).
  4. In Orders!D2, calculate the line total: =B2*C2.
  5. In a summary cell, total everything with =SUM(D:D), or isolate one product with =FILTER(A2:D20, A2:A20="SKU-104").
C2fx=XLOOKUP(A2, Products!A:A, Products!C:C)
ABCD
1SKUQtyPriceTotal
2SKU-104312.5037.50
C2 pulls the price from the Products sheet based on the SKU in A2.

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

Related functions

Get new guides by email

Occasional emails when new Google Sheets guides and formula tutorials are published.