I have the address of the beginning and end of a range stored in especial cells like below:
I want to use SUM function on this range like this:
SUM('P&L'!C3:'P&L'!D3)
I tried the INDIRECT function but I face an error:
=SUM(INDIRECT(F2 & ":" & F3))
Function INDIRECT parameter 1 value is ''P&L'!C3:'P&L'!D3'. It is not a valid cell/range reference.
Looking at the sample data below
P&L:
You could just use indirect to both ranges since both will then return cell references, and then sum those references and combine into a single range using :.
Formula:
=sum(indirect(F2):indirect(F3))
These two formulas work. See this google sheet for examples.
=sum(INDIRECT("'P&L'!C3:D3",true))
=sum(INDIRECT(F2&":"&F3,true))
=sum(INDIRECT("'P&L'!"&'P&L'!F2&":"&'P&L'!F3,true))
Also, this will create a volatile formula, a better choice would be to use Index as a range.
Please try the following
In your cells use P&L!C3 and P&L!D3
Your formula would be:
=SUM(INDIRECT(A4),INDIRECT(A5))
where A4 and A5 are your cells
Related
I have this formula that checks for the 2nd(onwards) instance of duplicate using 2 columns. I want it to be automatically applied to new rows but can't seem to figure out how to use ARRAYFORMULA for COUNTIFS. Can anybody please help me convert this formula =COUNTIFS($K$2:$K2, $K2, $T$2:$T2, $T2)>1 to an arrayformula or something similar? Thanks!
MAP() function may be a good solution. Try-
=MAP($K$2:INDEX($K$2:$K,COUNTA($K$2:$K)),$T$2:INDEX($T$2:$T,COUNTA($K$2:$K)),LAMBDA(x,y,COUNTIFS($K$2:$K,x,$T$2:$T,y)>1))
K2:INDEX(K2:K,COUNTA(K2:K)) will return a array of range from K2 to next non empty cell of K column.
Same T2:INDEX(T2:T,COUNTA(K2:K)) will return a array of range from T column still base on K column last non empty cell.
Edit: As per comment, try below formula-
=INDEX(MAP(A2:INDEX(A2:A,COUNTA(A2:A)),C2:INDEX(C2:C,COUNTA(A2:A)),LAMBDA(x,y,COUNTIFS(A2:A,x,C2:C,y,ROW(A2:A),"<="&ROW(x))>1)))
Change ranges for your sheet.
I am writing a formula in Google Sheets. Here's the formula;
=IF(COUNTIFS(C$3:ADDRESS(ROW(INDEX(A2:A,COUNT(A2:A))),3), C3, E$3:ADDRESS(ROW(INDEX(A2:A,COUNT(A2:A))),5), E3, F$3:ADDRESS(ROW(INDEX(A2:A,COUNT(A2:A))),6), "<>0") > 1, "MULTIPLE POSITIVE LBS THAT'S GREATER THAN ZERO", MINUS(F3, SUMIFS(G$3:G$480, C$3:C$480, C3, E$3:E$480, E3)))
Now the formula works like this but it only sums the values between row 3 and 480. What I want to do is get all the values between row 3 and the last non-empty field. In order to achieve that I used this formula;
ADDRESS(ROW(INDEX(A2:A,COUNT(A2:A)))
I was able to make this formula work for countif function but when I use the same formula in sumif function, it gives me Argument must be a range error.
This is the second version (the one giving an error)
=IF(COUNTIFS(C$3:ADDRESS(ROW(INDEX(A2:A,COUNT(A2:A))),3), C3, E$3:ADDRESS(ROW(INDEX(A2:A,COUNT(A2:A))),5), E3, F$3:ADDRESS(ROW(INDEX(A2:A,COUNT(A2:A))),6), "<>0") > 1, "MULTIPLE POSITIVE LBS THAT'S GREATER THAN ZERO", MINUS(F3, SUMIFS(G$3:ADDRESS(ROW(INDEX(A2:A,COUNT(A2:A))),7), C$3:ADDRESS(ROW(INDEX(A2:A,COUNT(A2:A))),3), C3, E$3:ADDRESS(ROW(INDEX(A2:A,COUNT(A2:A))),5), E3)))
I also tried to make ADDRESS function work independently, in a completely different cell and it gives the correct address.
This is the first time I'm writing sheets or any kind of excel formula so I couldn't find the source of the problem. What am I doing wrong?
Replacing ADDRESS(ROW(INDEX(A2:A,COUNT(A2:A))) with C$3:INDEX(C2:C,COUNT(A2:A)) did the trick. Apparently ADDRESS returns a string rather than a reference.
Address function returns a string. Which is not accepted as an input for sumif function So you have to convert the string returned by the address function to a reference. To do this, use the indirect function.
Like so: INDIRECT(address(2,row()-1,4,TRUE,"MAIN"))
Now you can use this as an input to many other functions like sumif, column, row, etc.
I was looking a the formula for cumulative sum using arrayformula:
ARRAYFORMULA(SUMIF(ROW(A1:A10), "<=" & ROW(A1:A10), B1:B10))
I used arrayformulas before, but mostly for simple arithmetic, so I am trying to wrap my head around this.
The reason it is unclear for me is that I don't know what the rules are for ARRAYFORMULA to use the range, or to use the scalar value.
If I tabulate it it becomes something like this:
row 1: SUMIF(ROW(A1:A10), "<=" & ROW(A1), B1:B10))
row 2: SUMIF(ROW(A1:A10), "<=" & ROW(A2), B1:B10))
...
row n: SUMIF(ROW(A1:A10), "<=" & ROW(An), B1:B10))
But that doesn't actually work because ROW doesn't work like that if not used in an ARRAYFORMULA, according to the docs:
ROW([cell_reference])
if cell_reference is a range more than one cell wide and the formula is not used as an array formula, only the numeric value of the first row in cell_reference is returned.
Looking at the syntax for SUMIF it is:
SUMIF(range, criterion, [sumrange]).
Do I understand it correctly that the rules for ARRAYFORMULA are:
If a function parameter inside ARRAYFORMULA is expected to be a scalar (criterion in the examle) and a range is given it will expand in the cells below iterating this range
If a function parameter inside ARRAYFORMULA is expected to be a range (range and sumrange) and a range is given it will pass on the range to the formula
So, the question is:
What is exactly happening row by row with the formula pasted above and how does ROW behave in this? ROW is 'aware' that it is being used in an arrayformula and behaves differently?
It's not about the ROW. Its more about the & and the strings used. Used inside a arrayformula, it creates series(a array) of strings. So, "<="&ROW(A1:A10) becomes "<1","<2" and so on. Criterion argument of SUMIF expects a string and only a single string. Given the array, it creates a array of results for each criterion, the Range argument being the same for each criterion. Also, SUMIF already expects array for the range argument.
I've been at this problem for a while now. I am trying to sum numbers under a specific column when the rows equal a certain text and then display that sum on a different sheet. So far I came up with this formula: =IF(EXACT(A2,Table!A2:A)=TRUE,SUM(Table!C2:C)); however the only problem is that is sums everything in column C (which makes sense).
I wish there was a way to do something like the following: SUM(Table!C2:C where EXACT(A2,TABLE!A2:A)=TRUE). I've also tried the SUMIF(), DSUM(), and QUERY() functions to no avail. I must be getting logically tripped up somewhere.
Figured it out: =SUM(FILTER(Table!E4:E, EXACT(Table!A4:A,A4)=TRUE)).
=sum ( FILTER (b1:b10, a1:a10 = "Text" ) )
// the above formula will help you to take the sum of the values in column B when another column A contain a specific text.
The formula is applicable only in Google Spreadsheets
For example you have A1 = {1;2;3}
So, if you want to make cumulative sum in B1 you make this:
B1 = ARRAYFORMULA(SUMIF(ROW(A1:A3);"<="&row(A1:A3);A1:A3))
Or more flexible variant:
B1 =ARRAYFORMULA(SUMIF(INDIRECT("A1:A"&COUNTA(A:A));"<="&INDIRECT("A1:A"&COUNTA(A:A);INDIRECT("A1:A"&COUNTA(R:R)))))
This variant expands according to length of Array in A1 and does not grow to the end of the sheet.
I want to use value of A1 directly in formula like:
=ARRAYFORMULA(sumif(row({1;2;3});"<="&row({1;2;3}));{1;2;3})
But it will not accept {}, because it requires range, but not array.
Does anyone have a trick to override this behavior?
Short answer
=ArrayFormula(sumif({1;2;3},"<="&{1;2;3}))
Explanation
The sintax of SUMIF is SUMIF(range, criterion, [sum_range])
sum_range is an optional parameter to be used when it's different from range. As sum_range and range are the same then the trick is not to use sum_range.
Reference
SUMIF - Docs editors Help