How to aggregate data from different rows and columns for further processing.
Introduction
There are many ways in which aggregated data can be used. You might need to grab an array of data from different rows or produce a sorted and unique list of items from some columns. Commonly these aggregations are often used as inputs for other functions and are known as arrays in the Google Sheets product documentation.
Basic Arrays
Arrays are built using the curly brace syntax ({LIST OF RANGES}). Ranges of cells are addressed in the normal way (e.g. A1, A:A, A2:C etc.) but are delineated by either a comma (,) or a semicolon (;). The delineating character essentially sets the direction (comma = horizontal, semicolon = vertical) of the output array.
Fruit 1 | Fruit 2 | Fruit 3 |
---|---|---|
Apple | Guava | Satsuma |
Apricot | Melon | Tamarind |
Avocado | Mango | Yuzu |
Banana | Mulberry | Pomegranate |
Blackberry | Nectarine | Pear |
Bilberry | Orange | Plum |
Blackcurrant | Elderberry | Strawberry |
Blueberry | Gooseberry | Pineapple |
Currant | Grape | Avocado |
Boysenberry | Grapefruit | Damson |
Cherry | Tangerine | Date |
If you wished to pull these three columns together into a single column/array, you could use the following formula.
If you wanted a single row containing all these fruits, then you could do this.
Arrays within Functions
That was inelegant and tiresome to type, but you get the idea. The easiest way to swap the orientation would be to wrap our array in a transpose function.
This is much more useful, as we are using the array as an input to another function. It is particularly helpful when we want to sort our array or output unique values.
In the second example above, we are using a query function to remove any blank entries from our output list (by way of a ‘where’ condition). This is particularly useful as it allows us the aggregate the entire columns and not have to change our formula every time we add more data. Similar to using query with importrange, when using an array as a data source for a query, you can’t address the columns by their letter headings anymore. Instead, you have to use the Col1, Col2, Col3 naming unless you specify a heading row.
We can also use our array as an input into a query or sparkline function. The latter is particularly useful as it allows the selective use of data from a single row as the source for a sparkline. So, instead of having to use a contiguous set of cells in your sparkline, you can pick and choose.
Any function that accepts a range can also normally accept an array, just make sure that you get the orientation correct!
Related ► Google Calendars on the Web (01 Sep 2018), Protecting Data with Google Drive (14 Aug 2018), Dealing with confidential information in schools (24 Jul 2018)