Section: Excel & Google Sheets

ARRAY_CONSTRAIN in Google Sheets cuts an array down to a set number of rows and columns. It is the function to reach for when a formula returns more than you want to show: a SORT over a thousand rows, a QUERY with more columns than the report needs, or an ARRAYFORMULA that runs past the table. This guide covers the syntax, worked examples, and how it compares with TAKE and DROP in Excel.
What ARRAY_CONSTRAIN does
Google's description is one line: it constrains an array result to a specified size. You give it a range or a formula result, the number of rows you want and the number of columns you want, and it returns that top-left block.
Google's note explains the usual reason to use it: it is generally used with other functions that return an array result when fewer rows or columns are wanted. In other words, it is a trimmer, not a data tool.

The syntax
=ARRAY_CONSTRAIN(input_range, num_rows, num_cols)
- input_range is the range or array to constrain.
- num_rows is how many rows the result should contain.
- num_cols is how many columns the result should contain.
Both counts are required. There is no way to say "all rows, three columns" by leaving a number out, so pass a number large enough to cover the data when you only care about one direction.
Constrain a plain range
Google's first sample is =ARRAY_CONSTRAIN(A1:C10,2,3). That returns the top-left two rows and three columns of the range, which is the same as reading A1:C2 by eye.
On a plain range the function looks pointless, and mostly it is. The value appears when the input is not a fixed block but a result that changes size.

Constrain a formula result
The second sample shows the real use: =ARRAY_CONSTRAIN(SORT(A1:F100,1,TRUE),10,6). SORT returns all hundred rows sorted by the first column, and ARRAY_CONSTRAIN keeps the first ten rows and six columns of that sorted result. You get a top-ten table that re-sorts itself when the data changes.
The order matters. Constrain after the sort, not before, or you will take ten arbitrary rows and then sort those.
Where it fits with ARRAYFORMULA
ARRAYFORMULA widens a formula so it fills rows or columns. ARRAY_CONSTRAIN does the opposite and caps the result. Put them together when a calculation runs over a whole column but the report only shows a block: the ARRAYFORMULA does the work, and ARRAY_CONSTRAIN decides how much of it appears.
That combination is also a fix for a common annoyance. An ARRAYFORMULA over an open-ended column can spill thousands of blank-looking cells, and the ARRAYFORMULA examples cover the usual workarounds; capping the output with ARRAY_CONSTRAIN is one of them.

ARRAY_CONSTRAIN compared with TAKE and DROP
Excel's newer dynamic array functions do a similar job with more control. TAKE keeps the first or last rows and columns, DROP removes them from the start or end, and both accept negative numbers to work from the bottom or the right.
ARRAY_CONSTRAIN only ever returns the top-left block, and both counts are mandatory. That is a limit, but it also makes the formula short and easy to read: two numbers, and you know exactly what comes back.
If you need the last rows instead of the first, sort the data the other way with SORT and constrain from the top. That is the Sheets way to get what TAKE does with a negative number.
Three uses worth knowing
First, a fixed-size dashboard block fed by a SORTN or SORT result, so the layout never grows into the charts below it. Second, trimming a QUERY that returns more columns than the report has room for. Third, limiting a lookup spill so a single formula does not collide with the cells around it.

Common problems
- The result is cut short. num_rows or num_cols is smaller than the data. Raise the number.
- Wrong rows appear. The constrain ran before the sort, so it trimmed unsorted data.
- #REF! error. The cells the result needs are occupied.
- Nothing but the first value. The formula sits inside a function that expects a single cell.
- Blank rows at the bottom. num_rows is larger than the data, so empty cells are included.
Questions and answers
What is ARRAY_CONSTRAIN used for?
Limiting an array result to a set number of rows and columns.
Does it sort the data?
No. It returns the top-left block of whatever it is given, so sort first if order matters.
Can I leave out the column count?
No. Both num_rows and num_cols are required.
Does Excel have ARRAY_CONSTRAIN?
No. Excel uses TAKE, DROP and CHOOSECOLS instead.
Will it work on a QUERY result?
Yes. Any function that returns an array can be the input.
