INDIRECT FUNCTION doesn't work in Google Sheets - 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"))

Related

Adding or subtracting values based on a vector of check boxes in Google Sheets

I hope you can help me with this:
I'm trying to create a savings-control sheet where I list my monthly payment and I'm trying to use the SUMIF formula to subtract my expenses by selecting what I have currently payed but I don't know if this may work with a vector of check boxes Sheets sample
the current formula as you can see in the image works fine but only for column D however if I check the rest of the boxes nothing is subtracted
This is how the formula looks like now: =A31+A32-SUMIF(D3:J14,TRUE,C3:C14) however only works from D3 to D14 and I need it to work from D3 to J14
Any help will be highly appreciate
I think the simplest solution is:
=A31+A32-SUM(ARRAYFORMULA(N(D3:J14)*C3:C14))
Formula rundown
This formula is based on the function N that converts a boolean to an integer (1 for true, 0 for false). We can then multiply by the expense value. Here an example:
=N(D3)*C3
This will equal C3 iff D3 is checked.
Having that we can make the entire table with ARRAYFORMULA:
=ARRAYFORMULA(N(D3:J14)*C3:C14)
Now we can sum all the values to have the total expenses:
=SUM(ARRAYFORMULA(N(D3:J14)*C3:C14))
Add the other cells and you get your result.
References
N (Docs Editors Help)
ARRAYFORMULA (Docs Editors Help)
SUM (Docs Editors Help)
Try
=A31+A32-sumproduct((countif(if(D3:J14, row(D3:D14)), row(D3:D14))>0),C3:C14)
and see if that helps?

Google Sheets limit on function

I have formula that I've been using for a while however the formula doesn't work properly anymore.
This is the formula:
=ArrayFormula(INDEX(FILTER(C3:HG3,(C2:HG2="keyword")*(C3:HG3<>"")),1,COUNTIFS(C2:HG2,"keyword",C3:HG3,"<>")))
From time to time I expend the columns and populate them with data.
I started using the formula somewhere from column FX now to column HG and I would like to expend it to column HJ but the formula doesn't work anymore. Is there a limit on calculations on formula's in Google sheets?
try:
=INDEX(INDEX(FILTER(C3:HJ3, (C2:HJ2="keyword")*(C3:HJ3<>"")), 1,
COUNTIFS(C2:HJ2, "keyword", C3:HJ3, "<>")))

Google Sheets ARRAYFORMULA and SUMIF combination

I recently noticed a mistake in my calculation, and I've identified the root cause of the problem: it seems that I mistakenly used the SUMIF function in Google Sheets' ARRAYFORMULA.
I have the sample spreadsheet here.
I wrote the ARRAYFORMULA function that results in column C, which I thought would be the same with the formula in column B.
The formula in column C:
=ARRAYFORMULA(SUMIF(H$3:H$6&I$3:I$6,"<="&A3:A31&">="&A3:A31,G$3:G$6))
The formula in column B:
=SUMIFS(G$3:G$6,H$3:H$6,"<="&A3,I$3:I$6,">="&A3)
In essence, I want to get the value for each date based on predefined values with their own periods.
Please, use this formula in the cell C3:
=ARRAYFORMULA(MMULT(IF((A3:A31>=TRANSPOSE(H3:H5))*
(A3:A31<=TRANSPOSE(I3:I5))=1,TRANSPOSE(G3:G5),0),ROW(G3:G5)^0))
I made a new tab called MK.Help and erased all the other formulas. then i put this formula in C3:
=ARRAYFORMULA(ARRAY_CONSTRAIN(MMULT(N(A3:A>=TRANSPOSE(A3:A)),MMULT((A3:A>=TRANSPOSE(H3:H))*(A3:A<=TRANSPOSE(I3:I)),N(G3:G))),COUNTA(A3:A),1))
Does that work for you?

How to get a value from a different sheet if two cells match in Google Sheets

I'm trying to do something that would be simple in Excel, but in Google Sheets you have to use INDIRECT in a formula to get a value from a different sheet.
All I want to do is pull the value in Sheet1!B2 if Sheet1!A2 equals A2.
I tried it several ways, below are a couple
=IF(Sheet1!A2=A2),INDIRECT("Sheet1!B2")
and
=INDIRECT("Sheet1!B2")IF(Sheet1!A2=A2)
in Google Sheets you have to use INDIRECT in a formula to get a value from a different sheet
is not correct.
Try:
=if(A2=Sheet1!A2,Sheet1!B2,"")
If that does not return the content of Sheet1!B2 then A2 does not equal Sheet1!A2 (even if they look the same).

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