Skip to main content

Looking up rows in a spreadsheet

How the lookup tools find matching rows in Google Sheets and Excel workbooks, and how to lay out a sheet so they work

The lookup tools find the rows of a spreadsheet that match conditions an agent gives them: lookup_sheet for Google Sheets and lookup_excel for Excel workbooks on Microsoft 365. On a large sheet they are cheaper and more accurate than reading page after page and searching by eye.

This article covers how a lookup picks its sheet and its columns, how matching works, and the sheet layout it expects. For reading and writing spreadsheets in general, see Working with Spreadsheets.


Opening the workbook and the tab

A lookup has no "which file" argument. It searches the tab the agent currently has open, so the agent opens the workbook by its URL first and then looks up.

To search a particular tab, put it on the URL: #sheetName=Inventory (or #sheetIndex=, or #gid= on Google Sheets). With no tab on the URL, the lookup searches the first tab. If a lookup finds nothing, the agent is told which tab it searched and which columns it has, so it can open a different tab and try again. The URL clauses are listed in Working with Spreadsheets.

The lookup tools are part of the Google Drive and Microsoft 365 connections. The connection has to be on the thunk, with its Google Sheets or Microsoft Excel tools enabled.

The header row

A lookup takes its column names from the first row of the tab: row 1 on Google Sheets, and on Excel the first row of the tab's filled area, which is row 1 for most sheets.

  • The column names are read from left to right and stop at the first empty header cell. A column to the right of an empty header cannot be searched.

  • Every row below the header is searched. Matching rows come back with their sheet row numbers, the same numbers the spreadsheet shows down its left edge.

Title rows

Many report-style sheets put a title in row 1 ("Q3 status report") and the real headers in row 2 or 3. A lookup has no setting to skip those rows. It reads the title row as the header, so it sees one column named after the title, and a search on the real columns finds nothing.

If a lookup on a sheet like that returns no rows, change the sheet's layout:

  • Move the title out of the top rows, for example into the tab name or a cell to the right of the data, so the headers are in row 1.

  • Or keep the report as it is and have the data on another tab that starts with its headers, then point the lookup at that tab with #sheetName=.

How matching works

An agent gives a lookup one or more conditions. Each condition names a column and says what to match in it. A row is returned only when it meets every condition.

Condition

Matches a cell when

A single value

the cell holds exactly that value.

A list of values

the cell holds exactly one of the values.

Contains a value

the value appears anywhere in the cell's text.

An empty value ("")

the cell is empty. It does not match every row.

  • Matching ignores upper and lower case: shipped matches Shipped.

  • An exact match compares the whole cell. Washington does not match Washington DC; use a contains condition for that.

  • Column names can be given as they appear in the header, such as Order Id.

A lookup can also say which columns to return, so a wide sheet comes back with only the columns the agent needs, and can ask for the first matching row only.

When to read the sheet instead

For a small sheet, opening it already shows every row, and the agent does not need a lookup. To go through every row of a large sheet in order, read it in blocks with #rowRange= as described in Working with Spreadsheets. Use a lookup when you know what you are looking for.

Did this answer your question?