ARRAY_CONSTRAIN: Google Sheets Function ☝️Explained (Definition, Syntax, How to Use It, Examples)

This guide covers everything you need to know about the Google Sheets ARRAY_CONSTRAIN Function: its definition, syntax, use cases, examples, and usage notes.

What Is the ARRAY_CONSTRAIN Function?

The ARRAY_CONSTRAIN function in Google Sheets allows you to limit or “constrain” an array result to a specific size. Essentially, it enables you to control the number of rows and columns that the result of your array should contain.

The main purpose of the ARRAY_CONSTRAIN function is to help manage large datasets. When working with such datasets, it’s often the case that you don’t need to work with or display all the data at once. This function allows you to focus on a specific portion of your data by setting a limit on the number of rows and columns you want to work with. This makes it easier to handle and analyze large amounts of data, as you can focus on the most relevant parts.

Typically, the ARRAY_CONSTRAIN function is used in conjunction with other functions that return an array result. For instance, you might use it with the SORT function to sort a range of data and then limit the result to a certain number of top or bottom rows.

It’s worth noting that the ARRAY_CONSTRAIN function doesn’t modify the original data in any way. It simply limits the amount of data that is returned by an array function. This makes it a safe and non-destructive way to manage your data.

In summary, the ARRAY_CONSTRAIN function is a useful tool in Google Sheets for managing large datasets by allowing you to limit the size of the array result. It’s typically used in combination with other array functions to provide a more manageable view of your data.


The ARRAY_CONSTRAIN function in Google Sheets constraints an array result to a specified size. Let’s delve into the syntax and its arguments:


ARRAY_CONSTRAIN(input_range, num_rows, num_cols)


  • input_range: This is the cell range that you want to constrain. It’s a required argument. For instance, to constrain the data from cells A1 to C10, you would use A1:C10 as the input_range.
  • num_rows: This argument determines the number of rows the output array should have. It’s a required argument and should be a positive integer. If the provided number exceeds the rows in the input_range, the function will display all the rows from the input_range. As an example, if you wish for the output to contain only 2 rows, use 2 for this argument.
  • num_cols: This is about setting the number of columns for the resulting array. It’s also a required argument and should be a positive integer. If the input value surpasses the columns in the input_range, the function returns all the columns from the input_range. For example, inputting 3 means the output should have 3 columns.

Examples of How to Use the ARRAY_CONSTRAIN Function

Understanding the syntax is only half the journey; applying it is where the true magic happens. To help cement your understanding of the ARRAY_CONSTRAIN function, let’s walk through a few practical examples.

Example #1: Basic Constrain

Suppose you’ve populated cells A1 through A10 with a list of ten items in Google Sheets. However, you’re interested in displaying just the top 5 items.

Formula: =ARRAY_CONSTRAIN(A1:A10, 5, 1)

This will display only the first five items from the list in your chosen location.

Example #2: Combining with SORT

Assuming you have a dataset from A1 to B10 in Google Sheets, representing products and their respective sales, and you wish to display only the top three selling products.

Formula: =ARRAY_CONSTRAIN(SORT(A1:B10, 2, FALSE), 3, 2)

This will sort the products by sales in descending order and present the top three.

Example #3: Working with Wider Ranges

Imagine you’ve tabulated student names and their marks in three subjects from A1 to D20 in Google Sheets. You wish to present only the names and scores of the first two subjects for the top five students.

Formula: =ARRAY_CONSTRAIN(A1:D20, 5, 3)

This will display the names along with the scores in the first two subjects for the initial five students.

Example #4: Pairing with QUERY

Let’s say you have a list spanning A1 to B50 in Google Sheets, showing cities and their respective populations. Your goal is to enlist the first three cities with populations exceeding one million.

Formula: =ARRAY_CONSTRAIN(QUERY(A1:B50, “select A, B where B > 1000000”), 3, 2)

This formula will display the names of the first three cities that have a population surpassing the 1 million mark.

These examples offer a glimpse into the versatility of the ARRAY_CONSTRAIN function, making it an indispensable tool in your Google Sheets arsenal. Play around with it, combine it with other functions, and soon enough, you’ll be crafting sheets like a pro!

Tips and Tricks Using ARRAY_CONSTRAIN

The deeper you delve into ARRAY_CONSTRAIN, the more its potential shines through. Here are some advanced tips and tricks to optimize your experience with this invaluable function in Google Sheets:

  • Highlight Key Data: When working with extensive datasets, use ARRAY_CONSTRAIN to focus on and showcase the most critical sections of your data. This approach can improve readability and ensure that significant data points stand out.
  • Dynamic Constraints with Functions: Instead of specifying a set number for rows or columns, use other functions like COUNTA to determine these values dynamically. For instance, to constrain data to the number of non-empty cells in a range, employ COUNTA to set the constraint.
  • Leverage with Import Functions: When you integrate ARRAY_CONSTRAIN with functions such as IMPORTRANGE or IMPORTXML, it allows for precise control over the displayed data. These functions can retrieve extensive data sets, and ARRAY_CONSTRAIN ensures that only the relevant sections are presented, maintaining a tidy sheet.
  • Visualize with Conditional Formatting: After constraining your data using ARRAY_CONSTRAIN, employ conditional formatting to quickly identify and analyze trends, patterns, or outliers in your chosen dataset.
  • Streamline Data Validation: If you’re sourcing dropdown lists from larger arrays, navigating through a vast number of options can be overwhelming. By employing ARRAY_CONSTRAIN, you can provide a concise, user-centric list, enhancing the user experience.
  • Facilitate Quick Data Sampling: In scenarios where you’re dealing with large datasets, a brief snapshot or sample can often suffice. Use ARRAY_CONSTRAIN to swiftly pull relevant sections from extensive datasets for initial analyses or overviews.
  • Craft Interactive Dashboards: Enhance the interactivity of your dashboards or reports in Google Sheets by using ARRAY_CONSTRAIN in tandem with sliders or dropdowns. This gives users the flexibility to select the number of rows or columns they wish to view, making for a more engaged and tailored experience.

Harnessing these advanced techniques can elevate your Google Sheets workflows, enabling you to use ARRAY_CONSTRAIN more effectively and innovatively.

ARRAY_CONSTRAIN: Common Mistakes & Problems

When working with Google Sheets, it’s only natural to occasionally run into some roadblocks or make a few errors, especially when dealing with powerful functions like ARRAY_CONSTRAIN. Here are some common issues and misunderstandings related to this function:

  • Mistaking the Order of Arguments: A frequent slip-up is getting the order of arguments wrong. Always remember it’s input_range, followed by num_rows, and then num_cols.
  • Providing Excessive Constraints: If you set the num_rows or num_cols values larger than the actual size of your input range, ARRAY_CONSTRAIN will simply return the original range size. It doesn’t add blank rows or columns.
  • Misunderstanding the Function’s Purpose: Some users expect ARRAY_CONSTRAIN to alter the original dataset. In reality, it only displays a constrained view. The original data remains unchanged.
  • Expecting Dynamic Adjustments: ARRAY_CONSTRAIN doesn’t automatically adjust if your input range grows or shrinks. If you added more data to your input range, you’d need to update the function manually to reflect the changes.
  • Neglecting Overflow Possibilities: When combined with functions that can produce varying output sizes, like QUERY or FILTER, it’s easy to forget about potential overflows. While ARRAY_CONSTRAIN can help by limiting the output, you should still be mindful of the data you might be omitting.
  • Using Non-numeric Values for num_rows and num_cols: Entering non-numeric values or references to cells with non-numeric values for num_rows or num_cols will result in an error. Always ensure these values are numeric.
  • Overshadowing Other Data: When placing the result of an ARRAY_CONSTRAIN function near other data, it’s possible that the array output might overshadow or overlap with existing data, causing confusion.

Awareness of these common pitfalls can make your experience with ARRAY_CONSTRAIN smoother. As with any function, practice and familiarity will reduce the chances of mistakes, and you’ll soon be optimizing your spreadsheets with ease.

Why ARRAY_CONSTRAIN Is Not Working? Troubleshooting Most Popular Errors

The ARRAY_CONSTRAIN function is a powerful tool in Google Sheets, but like any other function, it’s not immune to occasional hiccups. If you find that ARRAY_CONSTRAIN isn’t behaving as expected, here are some common errors users face and how to troubleshoot them:

#VALUE! Error

Cause: This usually pops up when non-numeric values are provided for the num_rows or num_cols parameters.

Solution: Double-check to ensure that the values or references you’ve provided for num_rows and num_cols are indeed numeric.

#REF! Error

Cause: This can arise if the input_range is invalid or if it references cells that don’t exist.

Solution: Verify the validity of your input_range. Ensure that you’re referencing a real range in your sheet and that you haven’t accidentally referenced cells outside the sheet’s limits.

Unexpected Output Size

Cause: If the output from ARRAY_CONSTRAIN doesn’t match the expected size, it’s possible that the num_rows or num_cols values provided are larger than the input range.

Solution: Remember that ARRAY_CONSTRAIN won’t extend the size of your original data. If you ask for more rows or columns than your data range has, the function will simply return the maximum available.

No Output or Missing Data

Cause: If you see fewer rows or columns than expected, it might be because you’ve provided a num_rows or num_cols value that’s too small.

Solution: Adjust the num_rows and num_cols values to fit the desired output size.

Misalignment with Other Data

Cause: If your constrained array seems to be pushing or overlapping with other data, the cause might be the placement of the function relative to existing data.

Solution: Ensure you’ve placed the ARRAY_CONSTRAIN function where there’s enough free space in your sheet to accommodate the desired number of rows and columns.

Function Not Updating Dynamically

Cause: If your input data changes in size but ARRAY_CONSTRAIN doesn’t adjust accordingly, it’s because the function isn’t designed to be dynamic in this way.

Solution: If your data range changes, you’ll need to manually adjust the input_range, num_rows, or num_cols as needed.

Using ARRAY_CONSTRAINT With Other Functions

In Google Sheets, the real power of a function often becomes evident when it’s combined with others. The ARRAY_CONSTRAIN function is no exception. By integrating it with other functions, you can unlock a myriad of spreadsheet capabilities. Here’s a guide on how to use ARRAY_CONSTRAIN in tandem with other Google Sheets functions:


Usage: The QUERY function can often return a vast array of results. By using ARRAY_CONSTRAIN alongside it, you can limit the display to only a specific section of those results.

Example: =ARRAY_CONSTRAIN(QUERY(A1:C10, “SELECT * WHERE C > 100”), 5, 3) – This would display only the first five rows of results where column C values are greater than 100.

With SORT:

Usage: When sorting a range, ARRAY_CONSTRAIN can be used to display only the top or bottom results.

Example: =ARRAY_CONSTRAIN(SORT(A1:C10, 3, FALSE), 10, 2) – This would sort the range based on the third column in descending order and then display only the first 10 rows and the first 2 columns.


Usage: When importing data from another spreadsheet, the output might be extensive. ARRAY_CONSTRAIN can limit the imported data to fit your needs.

Example: =ARRAY_CONSTRAIN(IMPORTRANGE(“SpreadsheetURL”, “Sheet1!A1:D20”), 10, 3) – This fetches data from another spreadsheet but only displays the first 10 rows and 3 columns.


Usage: After filtering a range based on certain conditions, ARRAY_CONSTRAIN can be used to restrict the number of filtered results displayed.

Example: =ARRAY_CONSTRAIN(FILTER(A1:C10, B1:B10=”Apple”), 5, 3) – This would show only the first five rows where column B has the value “Apple”.


Usage: If you’re splitting a text string into multiple parts, ARRAY_CONSTRAIN can ensure that only a specific number of these parts are displayed.

Example: =ARRAY_CONSTRAIN(SPLIT(A1, “,”), 1, 3) – If cell A1 had the text “Apple,Orange,Banana,Grapes”, this formula would display “Apple”, “Orange”, and “Banana” in separate cells.


Usage: After transposing a range (swapping rows with columns), ARRAY_CONSTRAIN can be applied to control the output’s dimensions.

Example: =ARRAY_CONSTRAIN(TRANSPOSE(A1:C3), 3, 2) – This transposes the data but restricts the output to 3 rows and 2 columns.

More Google Sheets Tutorials
More Microsoft Excel Tutorials
Share This Post
Daniel Smith
Daniel Smith
Daniel Smith is automation consultant with a passion for technology, data, AI, and machine learning.

The Spreadsheet Daddy add-on rebrands to Synterrix. Click here to learn more.