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
Related
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
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?
I have a column which won't sum? it sits beside a column with an array formula how is a sum done in this case?
This is my formula in C3:
ArrayFormula(query({M8Report!A2:T,arrayformula(left(regexreplace(M8Report!N2:N, "\n|\r", ""),150))},"Select Col5,Col2,Col1,Col21,Col3 Where (Col4 = 'Work Order') order by Col5", -1))
in B I have entered integer values in B1 I have =sum(B3:B) and the result is always 0 if instead in B1 I use B3+B4+B5+etc.. I get the correct result...
..Tried everything I can think of and same issue sum =0
since C is dynamic I need a way to sum all of the values in B
..any ideas would be helpful
In your sample sheet your formula is:
= { QUERY ; { "TOTAL" , SUM(B3:B) } }
Change it to:
=CONCAT("TOTAL ", SUM(B3:B))
The error has to do with your use of the {}, which is used to define an array literal. You just want to have 2 strings merged where one is the sum of the values. Also note that you may want to use B4:B instead since B3 is a header for the data below that.
Last, make sure the data is Numbers. The original data is formatted as Plain Text so SUM() has nothing to add.
to ditch formatting issues you can do:
={"Total", SUMPRODUCT(B5:B)}
Given data:
A1 = some value
A2 = operations needed like "*(-1) + today()"
Wanted result in A3 is formula which can take A1 and apply operations from A2.
Following my data sample if today is 10/25/2016 and A1 is 10/22/2016 I want to see "3" in A3.
Is this possible?
Yes this is possible by using Google Apps Script, getFormula or getFormulas methods.
Related question:
Is there a way to evaluate a formula that is stored in a cell?
I am trying to use FILTER and COUNTA in Google spreadsheet.
Spreadsheet
The formula in E1 is =COUNTA(filter($A$1:$A$12,$A$1:$A$12>=$C1,$A$1:$A$12<=$D1))
This formula help me to filter and count the date (Column A) which is within the date range (Column C and D).
The result in E1 and E2 is correct. However, E3, E4, E5 do not give me a zero, as there is no date fit in the range.
Anyone can help me on this to make it return a Zero if there is no date fit in the date range?
Martin. The function COUNTA is designed to count ALL values in a dataset, including repeats, zero-length strings, whitespace, and even "#N/A"s. So, you must wrap your FILTER formula in IFERROR, thus resulting in a truly empty cell where there is no date range match.
=COUNTA( IFERROR( filter($A$1:$A$12,$A$1:$A$12>=$C1,$A$1:$A$12<=$D1)))
You can read more in the Google Sheets documentation on COUNTA.