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