4

How can I dynamically rearrange a 2D range in Google Sheets into a 1D range, where the rows are "stacked" on top of each other, like shown below? When I say dynamically, I mean that the range is of a dynamic size using a FILTER, with a unknown number of columns (with a known number of rows though (52)). I have tried using the SPLIT(JOIN(range)) method seen on other questions, but that does not work here as JOIN requires the range(s) to be 1D.

Preferred Final Output

*Looking for Google Sheets solution if possible, but a Google Script would also be fine

Nick T
  • 63
  • 8

3 Answers3

4

For unknown number of cols and known rows you can just use:

=FLATTEN(TRANSPOSE(1:52))

enter image description here

basic
  • 11,673
  • 2
  • 9
  • 26
2

use this:

=QUERY(FLATTEN(TRANSPOSE(A1:C)), "where Col1 is not null")

enter image description here

player0
  • 124,011
  • 12
  • 67
  • 124
0

Of course the other answers are the most preferable for many reasons.

For documentation purposes and since you are open to a google apps script solution, here is a custom function that you could use:

function myFlat(rng) {
  const array = SpreadsheetApp.getActiveSheet().getRange(rng).getValues();
  return array[0].map((_, colIndex) => array.map(row => row[colIndex])).flat();
}

enter image description here

Marios
  • 26,333
  • 8
  • 32
  • 52