Going Stellar

Home/Google Sheets reference

Google Sheets function · Array

FLATTEN in Google Sheets: syntax and examples

FLATTEN takes a block of cells and returns every value in one column. It reads the range row by row, then moves to the next range. It is handy before SORT, UNIQUE, SUM or JOIN.

Syntax

FLATTEN(range1,[range2,...])

Arguments

ArgumentTypeRequiredWhat it does
range1rangeyesThe first range or array to flatten.
range2, ...rangenoMore ranges, appended below the first.

Examples

The examples use this table, starting in A1:

NameQ1Q2
Ana1020
Bob515
Cris78
=FLATTEN(B2:C2, B3)

Result:

10
20
5

A row and a single cell become one column, in the order given.

Run in a Google Sheet (English US locale) on .

=FLATTEN(A2:A3, A4)

Result:

Ana
Bob
Cris

Two ranges stacked into one column.

Run in a Google Sheet (English US locale) on .

=SUM(FLATTEN(B2:C4))

Result: 65

Flatten first, then aggregate: total of all values.

Run in a Google Sheet (English US locale) on .

=SORT(FLATTEN(B2:C2, B3), 1, FALSE)

Result:

20
10
5

The flattened values, largest first.

Run in a Google Sheet (English US locale) on .

=FLATTEN(A1:C1, A2:C2)

Result:

Name
Q1
Q2
Ana
10
20

Header row followed by the first data row, in one column.

Run in a Google Sheet (English US locale) on .

Common errors

  • The order is by rows, not by columns. To read down the columns first, transpose the range before flattening.
  • The first range is read completely before the next one is appended, so the order of arguments sets the order of the output.
  • FLATTEN returns one column even for a wide range. To lay the values out in a row, wrap the call in TRANSPOSE.

Compared with Excel

Excel has no FLATTEN. TOCOL (Excel 365) is the closest match, and Google Sheets has TOCOL as well.

Sources

  1. FLATTEN (Docs Editors Help)

Markdown version · All functions