What is ARRAY_CONSTRAIN in Google Sheets?

ARRAY_CONSTRAIN wraps an array formula result and returns only the first num_rows and num_columns of that output. It prevents huge spills, fits charts to fixed ranges, and stabilizes ranges for IMPORTRANGE wrappers when you need predictable dimensions.

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.

Build this without starting from a blank cell

Use a Better Sheets tool for ARRAY_CONSTRAIN, then watch a walkthrough when you want the full pattern.

Better Sheets resources

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

Browse 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 glossary terms

Done reading about ARRAY_CONSTRAIN?

Membership unlocks 636+ tutorials, unlimited generators, and every template. Practical lessons. Zero fluff.

Need this once

Jump to a free tool or a single tutorial for this topic.

Learning Sheets for real

Unlock the full library, generators, and templates with membership.