Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing a google spreadsheet array in one cell

Is it possible to store a google spreadsheet array in one cell, and then to refer to it?

I have a table, from which I have used FILTER to gather an array of relevant lines. I need to do several things with the filtered array: count the number of elements and sum the elements. Currently I have to repeat the FILTER function several times, because I can't host its output in one cell. It would be much nicer to store the FILTER output in a cell, and then have another cell with, say, "=SUM(B1)", and "=COUNT(B1)".

I have found that NOEXPAND disables adding CONTINUE cells, but then if I write "=COUNT(B1)" the result is 1 - I'm counting only the first item of the array.

Thanks!

edit: For some reason I couldn't answer my own question, but I found out that you can write your own functions in javascript. You can even serialize an array with JSON, and keep the result as a string. So, as a basic example, you can write:

function serialize(a) {
  return JSON.stringify(a);
}

function deserialize(a) {
  return JSON.parse(a);
}
like image 902
Noam Avatar asked Oct 06 '13 07:10

Noam


People also ask

Can you make a list in one cell in Google Sheets?

However, Google Sheets does include support for bullet points. There are two ways to add a bullet point to a cell in Sheets. You can also follow with ALT + ENTER to insert a line break if you wish to add multiple bullet points inside the same cell. Follow with CONTROL + OPTION + ENTER to insert a line break.

How do I merge data in one cell in Google Sheets?

Open your Google Sheet. Find the cells you want to combine and note their coordinates – in this example, A1 and A2. In the cell in which you want to display the combined data, type '=sum(A1, A2)'. You can also use a range in the sum formula, i.e., '=sum(A1:A2)'.

How do I keep all words in one cell in Google Sheets?

With a text cell selected, choose the Format | Text Wrapping | Overflow option. Text in a cell overflows adjacent blank cells. This is the default. In a text-heavy Google Sheet, you can choose Format | Text Wrapping | Wrap to make it so every word in a cell is displayed.


1 Answers

You can store an array as text in a single cell using JOIN.

It's less than ideal, as you still have to unmarshal it every time using SPLIT, but it's useful for storing complex filters.

For instance:

A1: =TRANSPOSE({1,2,3,4,5,6,7,8,9,10})
B1: =TRANSPOSE({3,1,1,2,1,1,1,1,1,0})
C1: =JOIN(",",FILTER(A1:A10, B1:B10 > 0, B1:B10 < 3))

COUNT(SPLIT(C1,",")) == 8

compared to

COUNT(FILTER(A1:A10, B1:B10 > 0, B1:B10 < 3)) == 8
like image 141
00500005 Avatar answered Sep 22 '22 10:09

00500005