How to Use the Google Sheets ARRAY_CONSTRAIN Function to Limit Output Sizes

When working with dynamic array functions in Google Sheets, such as FILTER, SORT, or UNIQUE, you often generate massive datasets that spill across hundreds of rows and columns. While powerful, these large outputs can quickly ruin the formatting of your dashboard or overwrite existing data below the formula. To regain control over your spreadsheet’s layout, you need to use the ARRAY_CONSTRAIN function.

What is the ARRAY_CONSTRAIN Function?

The ARRAY_CONSTRAIN function does exactly what its name suggests: it takes a large, dynamically generated array (a block of cells) and constrains its output to a specific, predefined number of rows and columns. It acts as a strict boundary for your data. If your base formula attempts to return 1,000 rows, but you only want to display the “Top 10” results on your executive dashboard, this function forces Google Sheets to truncate the output at exactly row 10.

Understanding the Syntax

The function requires three straightforward arguments:

=ARRAY_CONSTRAIN(input_range, num_rows, num_cols)

  • input_range: This is the data you want to constrain. It can be a simple cell range (like A1:Z1000) or another dynamic formula.
  • num_rows: The maximum number of rows you want the formula to display.
  • num_cols: The maximum number of columns you want the formula to display.

How to Limit the Output of a SORT Formula

The most common use case for this function is extracting a “Top X” list from a massive dataset. For example, imagine you have a list of 500 sales representatives in column A and their total revenue in column B. You want to display only the top 5 performers on a summary sheet.

  1. Click on the cell where you want the summary list to begin.
  2. Normally, to sort the entire list by revenue from highest to lowest, you would use:

=SORT(A1:B500, 2, FALSE)

However, this will output all 500 rows. To constrain this to only the top 5 rows (and keep both columns), wrap the SORT formula inside ARRAY_CONSTRAIN.

  1. Type the following formula:

=ARRAY_CONSTRAIN(SORT(A1:B500, 2, FALSE), 5, 2)

  1. Press Enter.

Google Sheets will calculate the full sort in the background, but will immediately truncate the visible output, displaying only a 5-row by 2-column grid containing your top sales representatives.

Using ARRAY_CONSTRAIN with IMPORTRANGE

This function is also highly effective when pulling data from external workbooks using IMPORTRANGE. If an external workbook contains thousands of rows, but you only need the header row and the first 20 data points, pulling the entire sheet wastes bandwidth and slows down your local file.

To pull only the first 21 rows (and 5 columns) from an external sheet, you would structure the formula like this:

=ARRAY_CONSTRAIN(IMPORTRANGE("spreadsheet_url", "Sheet1!A1:E"), 21, 5)

This ensures your local spreadsheet remains lightweight and responsive, regardless of how large the source document grows over time.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.