← Level 5 – Modeller

2 / 12 ⏱ 25 minutes Premium

Find a value in a table

Which snack won? The XLOOKUP function finds it by itself.

Looking things up

On the Dashboard, the Favorite snack cell is still empty. Now you’ll learn a formula that finds the winner by itself.

The XLOOKUP function finds something in one column and returns the matching value from another column.

=XLOOKUP(what I'm looking for, where I'm looking, what to return)

Find the winner

First, you find out how many votes the winner has. That’s the biggest number: =MAX(Survey!B2:B6) → 8.

Then you find which snack that 8 belongs to:

  1. On the Dashboard sheet, click on B5.

  2. Type =XLOOKUP(MAX(Survey!B2:B6),Survey!B2:B6,Survey!A2:A6).

  3. You’ll see sandwich.

You read it like this: “Find the biggest number of votes in column B, and give me the snack from the same row in column A.”

💡

Try changing the answers on the Answers sheet so that banana has more votes. The winner on the Dashboard changes by itself.

Older Excel

The XLOOKUP function is in Google Sheets and in Excel 365. Older Excel has VLOOKUP:

=VLOOKUP(what I'm looking for, table, which column to return, FALSE)

But VLOOKUP can only look in the first column of the table and return values to the right of it. It wouldn’t work for our winner, because the votes are to the right of the snacks. That’s why XLOOKUP is better.

⚠️

When two snacks have the same number of votes, XLOOKUP returns the first one. Watch out for a tie.

When it finds nothing

When XLOOKUP finds nothing, it shows the error #N/A. But you can tell it what to write instead of the error. You add a fourth part:

=XLOOKUP("pizza",Survey!A2:A6,Survey!B2:B6,"not on the list")

Giliranmu 💪

  1. B5 on the Dashboard shows the survey winner.
  2. When the votes change, the winner changes.
  3. You know what the three parts of XLOOKUP mean.
✅

Done when: the spreadsheet finds the survey winner by itself.

What to take away from this lesson