What is ARRAY_CONSTRAIN in Google Sheets?

When to use it

Use ARRAY_CONSTRAIN when a QUERY or FILTER might spill more rows than your dashboard slot allows, or when a chart needs a fixed height block.

When to skip it

Skip ARRAY_CONSTRAIN when you want the full dynamic spill. Truncating data silently hides new rows from reports.

How it works

  1. 1

    Wrap the array-producing formula as the first argument.

  2. 2

    Set num_rows to the maximum rows to keep from the top of the spill.

  3. 3

    Set num_columns to cap width similarly.

  4. 4

    Pair with QUERY LIMIT when SQL can limit at source instead of truncating after.

  5. 5

    Document that rows beyond the cap are hidden from view, not deleted at source.

  6. 6

    Increase caps when legitimate growth exceeds the constrained size.

Examples in Google Sheets

Cap QUERY spill

=ARRAY_CONSTRAIN(QUERY(Data!A:D, "select *", 1), 50, 4) shows at most fifty rows of query output.

Chart source block

=ARRAY_CONSTRAIN(SORT(A2:C), 12, 3) feeds twelve-month chart range even if source grows.

IMPORT trim

=ARRAY_CONSTRAIN(IMPORTRANGE(id, "Raw!A:Z"), 1000, 10) limits wide import while prototyping.

Common mistakes

  • Constraining so small that new data never appears in reports.
  • Using ARRAY_CONSTRAIN instead of fixing QUERY LIMIT at the source.
  • num_columns too narrow, cutting off critical fields without error.
  • Wrapping scalar formulas unnecessarily.
  • Forgetting constrained range still recalculates full inner formula cost.

Frequently asked questions

ARRAY_CONSTRAIN vs QUERY LIMIT?
QUERY LIMIT reduces work in SQL. ARRAY_CONSTRAIN trims any array output.
Does it hide errors?
Errors in visible constrained cells still show. Truncation is silent for extra rows.
ARRAY_CONSTRAIN and charts?
Fixed-size output helps chart ranges stay stable on dashboards.
Too few rows symptom?
New source rows exist but do not appear below the cap.
ARRAY_CONSTRAIN with FILTER?
Yes. FILTER then constrain to max dashboard height.
Can cap be dynamic?
Row and column counts can be cell references if they resolve to numbers.
ARRAY_CONSTRAIN vs TAKE?
TAKE is a newer function for first n rows or columns with similar goals.

Related Tutorials

Watch how ARRAY_CONSTRAIN works

Watch more tutorials
Spreadsheet Automation 101 Lesson 2: Arrays

Spreadsheet Automation 101 Lesson 2: Arrays

Learn the basics of Arrays – how to create one, how to reference rows an...

Related blog posts

Guides that explain ARRAY_CONSTRAIN in more depth.

Browse the blog

Related terms

Ads keep the free stuff free. Members browse ad-free — log in or see pricing.
Big Year 2027 calendar: the whole year on one Google Sheet

Free 2027 calendar.Plan all of 2027 on one Google Sheet, free.

Copy it to your Google Drive.

Free. No password, no card. The sheet link shows up right here.