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 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. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Calculate Trip Days by Month (Start, End, and Full Days) in Google Sheets

If you're managing business travel in Google Sheets, you may need to calculate how...

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...

More like this

Calculate Trip Days by Month (Start, End, and Full Days) in Google Sheets

If you're managing business travel in Google Sheets, you may need to calculate how...

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...

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.