XLOOKUP Visible (Filtered) Data in Google Sheets

Published on

This post describes how to use the XLOOKUP function on visible data in Google Sheets. I’ll show you how to achieve this using a LAMBDA-based LHF with the SUBTOTAL function.

We can temporarily hide unwanted or unused data in Google Sheets in 2–3 ways. The most popular options are the Filter (via Data > Create a filter) and Slicer.

I’m sure you’re familiar with those methods. There are a few others as well, such as:

  • View > Group > Group rows
  • Right-clicking on selected row(s) and choosing Hide row(s)
  • Data > Create group by view
  • Filters created via “Create a Table”

The Limitation of XLOOKUP with Hidden Rows

The XLOOKUP function has many flexible options for looking up values. But unfortunately, it does not have a built-in way to exclude hidden rows.

To XLOOKUP visible data in Google Sheets, we need to pair it with another function—SUBTOTAL.

However, the drawback is that SUBTOTAL isn’t an array formula—it doesn’t “spill” down rows automatically. To work around this, we can use a BYROW or MAP LHF (LAMBDA Helper Function).

These will allow us to expand or “spill” the SUBTOTAL results across multiple rows. I prefer the BYROW function for this purpose.

How to XLOOKUP Visible Data in Google Sheets

The XLOOKUP function offers several options to customize how a search key is matched—via match mode and search mode. I won’t go into those here since I’ve already covered them in detail in a separate tutorial.

Instead, we’ll focus on a simple example to help you understand how to use XLOOKUP with visible data in Google Sheets. If you have further questions, feel free to post them in the comments below.

Sample Data (Unfiltered)

We have a list of item codes in column A and corresponding quantities in column B. The data is currently unfiltered.

Let’s say we want to retrieve the quantity for the first item that ends with 1003. Here’s how we can do that using a wildcard match with XLOOKUP:

=XLOOKUP("*1003", A2:A, B2:B, "Not Available!", 2, 1)
Example of XLOOKUP using partial (wildcard) match in Google Sheets

XLOOKUP Partial Match – Explained

Syntax:

XLOOKUP(search_key, lookup_range, result_range, [missing_value], [match_mode], [search_mode])
  • search_key: "*1003"
  • lookup_range: A2:A
  • result_range: B2:B
  • missing_value: "Not Available!"
  • match_mode: 2 (wildcard match)
  • search_mode: 1 (search top to bottom)

Sample Data (Filtered) – XLOOKUP in Visible Data

Now let’s apply a filter to columns A and B:

  1. Select the range A1:B.
  2. Go to Data > Create a filter.
  3. Click the filter icon in cell A1.
  4. Choose Filter by condition > Custom formula is.
  5. Enter the following formula:
    =NOT(REGEXMATCH(A2, "(?i)^A"))
  6. Click OK.

This hides all rows where the values in column A start with the letter “A”.”

The Problem

Here’s the issue: when you use the same XLOOKUP formula—

=XLOOKUP("*1003", A2:A, B2:B, "Not Available", 2, 1)

—it still returns values from hidden rows.

Example of XLOOKUP not excluding hidden (filtered) rows in Google Sheets

The Solution: XLOOKUP Visible Data in Google Sheets

To XLOOKUP visible (filtered) data in Google Sheets, follow these steps.

Let’s use the following formula within XLOOKUP to identify which rows are visible:

BYROW(A2:A, LAMBDA(range, SUBTOTAL(103, range)))

Note: SUBTOTAL(103, ...) returns 1 for visible rows and 0 for hidden rows. See the BYROW function guide for more explanation.

This returns a series of 1s and 0s depending on each row’s visibility status.

Logic Behind the Lookup

We can combine the lookup_range and visibility markers (helper formula) into one searchable array by appending a delimiter (e.g., ^) and the SUBTOTAL result. We also modify the search_key accordingly.

To avoid conflicts if your search key already includes a number like 1, it’s safer to append something like "^1" instead of just "1".

Since we’re combining arrays, we must wrap the formula in ARRAYFORMULA to ensure proper evaluation.

Here’s the final formula to XLOOKUP visible (filtered) data in Google Sheets:

=ARRAYFORMULA(XLOOKUP("*1003^1", A2:A & "^" & BYROW(A2:A, LAMBDA(range, SUBTOTAL(103, range))), B2:B, "Not Available", 2, 1))

That’s it! Now your XLOOKUP will only return results from visible rows in filtered data.

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Expert Prashanth KV is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. With years of experience working with Google Sheets and Excel for multinational firms in Mumbai and Dubai, he has been blogging since 2012, offering practical, real-world spreadsheet solutions that professionals rely on. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Mode of Comma-Separated Numbers in Excel (Dynamic Array)

There is no dedicated function in Excel to directly find the mode of comma-separated...

How to Find Mode of Comma-Separated Numbers in Google Sheets

Working with comma-separated numbers inside a single cell is a common scenario in Google...

How to Count Merged Cells in Google Sheets (and Get Their Size)

Sometimes, you may have blocks of merged cells in a column or row. But...

Count Consecutive Workday Absences in Google Sheets

This tutorial offers a powerful formula-based solution to count consecutive workday absences in Google...

More like this

How to Find Mode of Comma-Separated Numbers in Google Sheets

Working with comma-separated numbers inside a single cell is a common scenario in Google...

How to Count Merged Cells in Google Sheets (and Get Their Size)

Sometimes, you may have blocks of merged cells in a column or row. But...

Count Consecutive Workday Absences in Google Sheets

This tutorial offers a powerful formula-based solution to count consecutive workday absences in Google...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.