Handle array size in Excel or Google Sheets - google-sheets

To create a 1x3 array in Excel or Google Sheets I can do:
={1,2, 3}
For example:
How would I create a multi-dimensional array, for example, a 3x3 array in Excel or Google Sheets?

Comma for columns, semicolon for rows (but it does depend on you language settings)
={1,2,3;4,5,6;7,8,9}

In Google Sheets and Excel, the union operator is ; so you can do:
'={1,2,3; 4,5,6; 7,8,9}

In Google Sheets you can use the following formula
=SEQUENCE(3,3)
Functions used:
SEQUENCE

Related

INDIRECT FUNCTION doesn't work in Google Sheets

I'm trying to sum a discontinuous range with SUM, COUNTIF and INDIRECT formulas. It works well in Excel, but when I upload my file in Google Drive and open it, the sum is different.
This is my formula. When I mark with X the cells D3, F3 or H3, I get the sum.
=SUM(COUNTIF(INDIRECT({"D3","F3","H3"},TRUE),"X"))
The same formula in Google Sheets only get the sum of D3, if I modify F3 or H3, the result doesn't change
Is there a way that you can function this formula in Google Sheets or get the sum of discontinuous cells?
Thank you!
In google sheets you can join the cells into a single array using curly brackets - you don't need the indirect:
=countif({D3,F3,H3},"X")
Having said this, GS isn't quite as flexible as Excel with indirect. If you had two different sized ranges like A1:B2 and C1:E3 and tried to combine them, GS would give a 'mismatched row size' error. You could get round it by flattening them like this:
=ArrayFormula(countif({flatten(A1:B2);flatten(C1:E3)},"X"))

How to loop over all sheets of a file in Google sheets?

I'm using Google sheets for storing some simple text. In a column (F) I have all names of sheets and I'm using the following to count occurrences of a certain string "aaa" in column C in all sheets:
SUMPRODUCT(COUNTIF(INDIRECT("'"&F3:F11&"'!C3:C200"),"*aaa*"))
It returns only occurrences in the first sheet. Any idea what is wrong?

How to convert Excel formula to Google Sheets?

This code calculates a sum of string lengths in the range H1:V5 using G as a row index and C as a column index. It works perfectly in Excel:
{=SUMPRODUCT(LEN(INDEX(H1:V5,N(IF({1},ROW(G2:G5))),N(IF({1},C2:C5+1))))*ISNUMBER(G2:G5))}
But when I try it in Google Sheets it doesn't work although Google Sheets recognizes all commands. Is it possible to convert my formula to Google Sheets? Or maybe there is some workaround to get the same result there?
Open with Google Sheets returns incorrect result:
=ARRAY_CONSTRAIN(ARRAYFORMULA(SUMPRODUCT(LEN(INDEX(H1:V5,N(IF({1},ROW(G2:G5))),N(IF({1},C2:C5+1))))*ISNUMBER(G2:G5))), 1, 1)
Unfortunately the construct index...n(if({1}... is peculiar to Excel.
The vlookup function in Google sheets is very versatile and you can use that instead:
=SUMPRODUCT(len(vlookup(row(H1:K5),{row(H1:K5),H1:K5},C1:C5+2,false))*isnumber(G1:G5))

Google Sheets equivalent for Excel's AGGREGAT formula

I am using Google Sheets and I need to implement following excel formula into my sheet.
https://docs.google.com/spreadsheets/d/1XzAYEezt2gNt_tdbxyZT-p6XwjNdhvUbt_9rBoABlhI/edit?usp=sharing
=IFERROR(INDEX(Formularantworten!B:B;AGGREGAT(15;6;ROW(Formularantworten!$B$2:$B$100)/(Formularantworten!$B$2:$B$100<>"")/(Formularantworten!$H$2:$H$100<>"");ROW(A1)));"")
Well if you want to match two columns and index a third column, finding the first match, you can do what you used to do in Excel before Aggregate came along:
=index(C:C,match(1,(A:A<>"")*(B:B<>""),0))
or
=index(C:C,min(if((A:A<>"")*(B:B<>""),row(A:A))))
But in Google sheets you have more options and are more likely to use something like
=query(A:C,"select C where A is not null and B is not null limit 1")

SUMIF across many sheets

I have a Google sheets document where several sheets have the same column layout. I'd like to sum column J if column G = "cat".
Essentially, this:
=SUMIF('A'!G3:G,"=cat", 'A'!J3:J) + SUMIF('B'!G3:G,"=cat", 'B'!J3:J) + SUMIF('C'!G3:G,"=cat", 'C'!J3:J)
But, with lots of sheets, that is cumbersome. How can I reduce that to something like this:
=SUMIF(INDIRECT({A,B,C}&"!G3:G"), "=cat", INDIRECT({A,B,C}&"!J3:J"))
excel has a solution with INDIRECT array-formula, see it here.
Unfortunately INDIRECT doesn't support iteration over an array in google-sheets
Syntax {A,B,C}&"!G3:G is not possible.
Workaround
The first step is to simplify the formula to:
=SUM(FILTER({Sheet1!B:B;Sheet2!B:B},{Sheet1!A:A;Sheet2!A:A} = "Cat"))
The hard part is to manually type all sheet names with ranges. I suggest to make a list of sheet names called Sheets_List:
Sheet1
Sheet2
And then use join to produce the proper formula text:
="{'"&JOIN("'!B:B;'",Sheets_List)&"'!B:B}"
The result is text "{'Sheet1'!B:B;'Sheet2'!B:B}", use it to build the formula.

Resources