How to Use Row Numbers as Filter Criteria in Google Sheets

Published on

When handling a large dataset, you might need to extract a portion of the data into a new range for further analysis, report generation, or printing purposes. If there are no specific criteria to filter the data, you can use row numbers as filter criteria in Google Sheets.

You may want to extract data from multiple portions of your dataset. In such cases, the formula may vary depending on how you specify the row numbers.

Example of Using Row Numbers as Filter Criteria in Google Sheets

Assume you have employee data in the range A1:E and you want to filter the records from rows 5 to 10. You can use the following formula:

=FILTER(A1:E, ISBETWEEN(ROW(A1:A), 5, 10))
Using Row Numbers as Filter Criteria in Google Sheets

The formula follows this syntax:

FILTER(range, condition1, [condition2, …])
  • Range: A1:E
  • Condition: ISBETWEEN(ROW(A1:A), 5, 10), which returns an array of TRUE or FALSE.

This formula filters the rows wherever the condition evaluates to TRUE.

The condition is actually an ISBETWEEN function, which works as follows:

ISBETWEEN(value_to_compare, lower_value, upper_value, [lower_value_is_inclusive], [upper_value_is_inclusive])
  • value_to_compare: The row numbers in the sheet.
  • lower_value: The starting row number to filter.
  • upper_value: The ending row number to filter.

Important Notes:

  • The condition and filter range must have the same number of rows.
  • If your range is A10:X100, then the value_to_compare must be ROW(A10:A100).

How Do I Specify Multiple Sets of Row Numbers as the Filter Condition?

If you want to filter rows from row #5 to 10 and row #20 to 25, the formula should be:

=FILTER(A1:E, ISBETWEEN(ROW(A1:A), 5, 10) + ISBETWEEN(ROW(A1:A), 20, 25))

This formula uses the + operator to combine multiple conditions, allowing you to filter non-contiguous sets of rows.

Filtering Non-contiguous Rows in Google Sheets

The above approach may not work well when you need to filter non-contiguous rows.

For example, if you want to filter rows 5, 10, and 15, you can use the following FILTER formula:

=FILTER(A1:E, XMATCH(ROW(A1:A), {5, 10, 15}))

In this formula, we use XMATCH to match the row numbers in A1:A with the specified array {5, 10, 15}. XMATCH returns the relative position of the matching rows and #N/A for the rows that don’t match. The FILTER function then filters the rows wherever XMATCH returns a valid number (relative position).

This approach allows you to filter non-contiguous rows, making it a flexible solution for such scenarios.

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.

Top N Products and Top N Sellers in Google Sheets (Top N of Top N)

If you’ve ever wanted to compare which sellers contribute the most to your top-selling...

Use XLOOKUP in a Structured Table in Google Sheets (Single and Multiple Conditions)

This tutorial is for users who want to apply XLOOKUP inside a structured table...

Reset SCAN by Another Column in Google Sheets and Excel

Resetting SCAN function results based on values in another column is a topic of...

How to Get the Fastest Time for Each Person in Google Sheets

Whether you’re tracking race results, event times, or any other timed activities, finding the...

More like this

Top N Products and Top N Sellers in Google Sheets (Top N of Top N)

If you’ve ever wanted to compare which sellers contribute the most to your top-selling...

Use XLOOKUP in a Structured Table in Google Sheets (Single and Multiple Conditions)

This tutorial is for users who want to apply XLOOKUP inside a structured table...

How to Get the Fastest Time for Each Person in Google Sheets

Whether you’re tracking race results, event times, or any other timed activities, finding the...

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.