VLOOKUP on a large file
VLOOKUP is the function everyone learns second, right after SUM. It brings a value from another table: the customer name for a customer code, the price for a product reference. On a few thousand rows it is instant. On hundreds of thousands it slows the workbook down, and beyond Excel’s million rows it cannot run at all. Here is how to use it well, and how to do the same lookup on a much bigger file.
How VLOOKUP works
VLOOKUP takes four arguments: the value to look for, the table to look in, the number of the column to return, and the match type. It searches the first column of the table for the value, then returns the cell in the same row, in the column you asked for.
=VLOOKUP(A2, Customers!A:D, 2, FALSE)Here Excel looks for the code in A2 in column A of the Customers sheet and returns the value of the second column, the name. FALSE asks for an exact match, which is almost always what you want.
The four classic VLOOKUP mistakes
- Forgetting FALSE. Without the fourth argument, Excel uses an approximate match, which assumes the table is sorted and silently returns a wrong row when it is not.
- Counting columns wrong. The column number is counted from the first column of the range, not from column A. Insert a column in the source and every VLOOKUP returns the wrong field.
- #N/A everywhere. The key is not found, often because of a trailing space, a code stored as a number on one side and as text on the other, or different capitals.
- Looking left. VLOOKUP can only return columns to the right of the key. That is why INDEX/MATCH and XLOOKUP exist.
Why VLOOKUP gets slow on big files
Each VLOOKUP cell searches the lookup table on its own. A sheet of 500,000 orders with one VLOOKUP per row runs 500,000 searches, and recalculates them whenever something changes. Add three looked-up columns and the workbook takes a long time to open, recalculate and save. And above 1,048,576 rows, the orders do not fit in a sheet in the first place.
VLOOKUP in Big Sheets: the same formula, on every row at once
Big Sheets is a spreadsheet for files of several million rows, running in your browser. It accepts VLOOKUP and XLOOKUP with their Excel names, in English or French. The difference is that a formula belongs to a whole column: you write it once, and the engine runs it on every row in a single pass, as a database join would.
You refer to columns by their names instead of cell ranges: the other sheet’s name, an exclamation mark, the column in brackets.
=VLOOKUP([@Code], Customers![Code], 2, FALSE)
=IFNA(VLOOKUP([@Code], Customers![Code], 2, FALSE), "Unknown")
=XLOOKUP([@Code], Customers![Code], Customers![Name], "Unknown")The key is compared as text and without regard to capitals, so 1 finds "1" and abc finds ABC. If several rows match, the first one wins. Without a fallback, a missing key gives an empty cell.
One difference from Excel to know: VLOOKUP in Big Sheets only does exact matches. Leaving out the fourth argument does not switch to approximate match.
No formula at all: the Lookup panel
If you would rather not write a formula, the Lookup panel does the same job with clicks.
- Open both files as two sheets.
- Click Lookup, and pick the other sheet.
- Choose the matching columns on each side, for example customer code and code.
- Leave Ignore case and spaces around the values ticked, so that “ACME ” matches “Acme”.
- Choose which columns to bring back, and click Look up.
The new columns appear in your sheet, with an icon in their header that reopens the lookup to change it later. Rows without a match stay empty, so they are easy to filter.
Lookup on two columns
When the key is made of two columns, such as a store and a product, join them with a separator on both sides:
=XLOOKUP([@Store] & "|" & [@Product], Prices![Store] & "|" & Prices![Product], Prices![Price])Check your lookups
- Filter the new column on empty values to see the keys that were not found, and why.
- Count the distinct keys in the lookup table: if a key appears twice there, only the first match is used.
- Spot-check a few rows by hand against the source table.
Try it on your own file
Open it in Big Sheets: no sign-up, and your file never leaves this browser.
One plan: €29 incl. VAT per month, everything included, cancel any time. See pricing
Questions
- Does VLOOKUP work on more than a million rows in Big Sheets?
- Yes. The formula runs on the whole column, on files tested up to 5 million rows.
- Is approximate match supported?
- No. VLOOKUP in Big Sheets only does exact matches, which is what most lookups need.
- Can I paste a VLOOKUP from Excel?
- Yes for the function names, in English or French. Cell ranges like A:D must be replaced by column names, for example Customers![Code].