Lookup Header and Filter Non-Blanks in Google Sheets

Published on

You can use the FILTER function to lookup a header and filter all non-blank values in that column in Google Sheets. Additionally, you can include the corresponding values from the first column of the table.

Generic Formulas

=LET(ftr, FILTER(data, row=G2), FILTER(ftr, ftr<>""))
  • Replace data with the range to filter (excluding the header row).
  • Replace row with the first-row reference of the data.
  • Replace G2 with the column header to lookup.

If you want to include the first column along with the filtered lookup column, use this formula:

=LET(ftr, FILTER(data, (row=G2)+(row=G3)), FILTER(ftr, CHOOSECOLS(ftr, 2)<>""))

Additionally, specify the first column header label in G3.

Let’s go through two examples to understand how to lookup a header, filter non-blanks in the found column, and optionally include the first column.

Example 1: Lookup Header and Filter Non-Blanks in the Lookup Column

Imagine you have a dataset where each column represents sales data for different regions (e.g., “North,” “South,” “East,” “West”), and the rows contain monthly sales figures. The first column contains month names. Some cells may be blank if there were no sales in a given month.

The goal is to dynamically select a region (column) by specifying the header (e.g., “East”). Once the column is identified, we extract only the non-blank sales values from that column for further analysis.

Sample Data (A1:E)

MonthNorthSouthEastWest
Jan35015050-150
Feb250100450
Mar300200350
Apr330220120400

Enter the region you want to lookup in G2, for example, “East”.

Enter the following formula in H2 to filter the column corresponding to the lookup value while removing blanks:

=LET(ftr, FILTER(A2:E5, A1:E1=G2), FILTER(ftr, ftr<>""))
Lookup a Header and Filter Non-Blank Values in the Corresponding Column

Formula Breakdown

  1. FILTER(A2:E5, A1:E1=G2) – Filters the range A2:E5, selecting the column where the header in A1:E1 matches G2.
  2. We use LET to name this result ftr.
  3. FILTER(ftr, ftr<>"") – Further filters ftr to remove blank cells.

Example 2: Lookup Header and Filter Non-Blanks + First Column

This time, the goal is to filter the selected region’s column while also including the first column.

Enter the region “East” in G2 and the first column header, i.e., “Month”, in G3.

Then, use this formula:

=LET(ftr, FILTER(A2:E5, (A1:E1=G2)+(A1:E1=G3)), FILTER(ftr, CHOOSECOLS(ftr, 2)<>""))
Lookup a Header, Filter Non-Blank Values, and Include the First Column

There is a specific benefit to including the first column. It helps identify the specific months with sales along with the sales figures.

Formula Explanation

  1. FILTER(A2:E5, (A1:E1=G2)+(A1:E1=G3)) – Filters A2:E5, selecting columns where the header matches G2 (East) or G3 (Month).
  2. We use LET to name this result ftr.
  3. FILTER(ftr, CHOOSECOLS(ftr, 2)<>"") – Ensures that only rows where the second column (East) is non-blank are returned.

Additional Tip

In both formulas, you can replace <>"" with >0 to filter out empty and zero-value rows:

=LET(ftr, FILTER(A2:E5, A1:E1=G2), FILTER(ftr, ftr>0))
=LET(ftr, FILTER(A2:E5, (A1:E1=G2)+(A1:E1=G3)), FILTER(ftr, CHOOSECOLS(ftr, 2)>0))

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Filter Top N per Category in Excel (Using FILTER & COUNTIFS)

You can use a combination of FILTER and COUNTIFS to filter the top N...

Rank per Group in Excel

You have two groups of 20 students each. How do you determine the rank...

Real-Time Excel Filtering Using Combo Box & FILTER Function

In this tutorial, you’ll learn how to set up real-time Excel filtering using a...

Google Sheets: Extract Top N per Group from Query Aggregation

When working with grouped and aggregated data in Google Sheets, you might need to...

More like this

Google Sheets: Extract Top N per Group from Query Aggregation

When working with grouped and aggregated data in Google Sheets, you might need to...

How to Extract Top N from Aggregated Query Results in Google Sheets

To summarize data in Google Sheets, you can use the QUERY function. However, if...

How to Use RANK IF in Google Sheets (Conditional Ranking)

You can use the RANK function to rank values in an entire dataset. But...

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.