Google Sheet Dynamic Sum - google-sheets

I am using google sheets to make a spread sheet and do some simple math, I figured how to do the summing but the problem is that I have about 180 rows of data and want to avoid, if possible, the need to make a formula for every single pair of data. Here is the simple code that I have:
=SUM(AG4:AG5)
So I am writing this code in this case in AH4 and is always the same relative placement to the values I want to add. I want the sum of the two numbers one column to the left and the current row and a row under that. Is there any way to make it so that the same formula can be used over and over instead of typing each one out. Maybe some way to make the formula look one column to the left take that number and add it to the cell one column to the left and one row down?
Thanks for any help you can provide.

You can use the ARRAYFORMULA function to apply a formula to multiple rows. It does not like some functions, though, and SUM() is one of them. So we need to use a different method to add the numbers. In this case, we just use AG4 + AG5. To apply the formula to all the rows in the spreadsheet we do a little more. Here is the formula, which would be placed in cell AG3 provided that is where the formula should start adding items.
=ARRAYFORMULA( IF( ISBLANK( AG3:AG),, AG2:AG + AG3:AG))
The IF ISBLANK AG3:AG) causes the formula to be applied to every row from row 3 to the last row in the sheet. ISBLANK will return FALSE on any row we want to work on so we provide nothing to teh TRUE portion of the IF statement. Note that I did not put "" in for the TRUE portion as that actually places a value in the row and can cause problems with other formulas. Since we are placing this in cell AG3 the addition will increment adding the row above to the current row.
EDIT from Comments
Placing this in cell AH2 will get you what you want:
=ARRAYFORMULA( IF( ISBLANK( AG2:AG),, IF(iseven( ROW(AG2:AG)),AG2:AG + AG3:AG,)))
Taking it a step farther, placing this in cell AH1 will label the header row for you and keep the formula out of the data rows. This has the advantage of allowing rows to be inserted above row 2.
=ARRAYFORMULA( IF(ROW(AH1:AH) = 1, "Total", IF( ISBLANK( AG1:AG),, IF(iseven( ROW(AG1:AG)),AG1:AG + AG2:AG,))))
The explanation is similar to above, only minor changes were made.
NOTE: The rest of column AH (below the formula) should not have any other manually entered data, so you will have to delete your formulas.

Related

SUMIF sum value in next column over

I'm trying to make use of the SUMIF function in Google sheets to sum up points if a cell below it is set to "Excused" However, the condition cell (what will be "Excused") and the points cell, are not in the same column.
The basic SUMIF formula I'm starting with is below
=SUMIF($B$9:$CW$9,$B12:$CW12,"=Excused")
I've tried to illustrate this below. Using ranges that go horizontally across the sheet in rows 9 and 12. If the red cell is set to "Excused", it should sum the blue cell.
With how the formula is, it tries to sum the cell in row 9 but in the same column as the cell with "Excused" in it. But, for example, if B12 has "Excused" in it, I want it to sum C9.
Hopefully, this makes sense. I've done my best to explain it, please ask for clarification if needed.
try:
=SUM(IFNA(FILTER(C9:CX9; B12:CW12="Excused")))

Refer to itself in ARRAYFORMULA

I am just wondering whether it is possible to achieve what I need to achieve, but using an ARRAYFORMULA.
I have a simple setup where in column B I show the value, which is present in the last previous filled in row in column A
Here is an example.
So, the questios is: is it possible to achieve the same, but with ARRAYFORMULA(s), so that in case a new row is incerted, one does not need to drag formula to fill in the new row, but the formula would be added automatically. All my attempts ended up with the circular reference problem.
This is tradtionally done with a vlookup of row numbers into a filtered array of the values. It would look like this in row 4 of your sample sheet:
=ARRAYFORMULA(VLOOKUP(ROW(A4:A),FILTER({ROW(A4:A),A4:A},A4:A<>""),2,TRUE))

How to Transpose Rows to Columns Towards Left Columns? In Google Sheet

SECOND IMAGE CLICK NUMBER 1 I Want To Transpose Row Value Range A2:A50 To Column CZ2 To BC2. Formula Should Be Given IN CZ2. AND VALUE SHOULD GET IN REVERSE OR LEFT COLUMNS.[First IMAGE Click Number 2] 2. If I Give Transpose (AO2:AO50) In CZ2 it Will go range from CZ2 To EW2. I Want Transpose in Reverse Columns. If I Increase Row Value AO2:AO60 It Should Flow Towards Left From CZ2 To AS2. I Mean Transpose Should work towards Left Side Columns. Its Ok with any other formula If Not Transpose. Hope My Question is Understandable. Someone Help Me Out. Thank You In Advance.
It's not clear why you would want to do this. However, the end goal can be achieved by placing the following formula in cell B2 (not CZ2):
=ArrayFormula(IFERROR(VLOOKUP(COLUMNS(B1:1)-COLUMN(B1:1)+ROW(A2)+1,{ROW(A2:A),A2:A},2,FALSE)))
Try it and you'll see what I mean.
The formula is written to be flexible. So if you add or subtract data from A2:A, the value in A2 will always be in Row 2 of the last column to the right in the sheet; and all other values will work backward from there.
If you always want to start to backward progression in Column CZ and Column CZ is not (or may not always be) your rightmost column, you can use this version:
=ArrayFormula(IFERROR(VLOOKUP(COLUMN(CZ1)-COLUMN(B1:CZ1)+ROW(A2)+1,{ROW(A2:A),A2:A},2,FALSE)))
Just understand that, if you don't have columns at least through Column CZ, this formula will fail to work as expected.
I recommend using the first formula I supplied above, since it will always work, no matter how many columns there are, filling backward as far as to the formula column (B2) as needed.
Understand also that if you have more than 103 rows of data in A2:A, that would be more than could fit between B2 and CZ2; so only the first 103 would be displayed.
ADDENDUM (after reading first two comments below):
The principle is the same if you want to run results from "CZ to BC"; only in this case, you want to limit the results to no more than 50.
Place the following formula in BC2:
=ArrayFormula(IFERROR(VLOOKUP(SEQUENCE(1,50,ROW(A2)+50-1,-1),{ROW(A2:A),A2:A},2,FALSE)))
To reiterate, you cannot run formulas that will fill or columns backward. (Even if the sheet is set to right-to-left font with Column A appearing at the far right, the formula is still filling A-Z according to that setup.) However, if you know that you want a 50-column range reserved and you want the answers to go backward, this can still be achieved by placing the formula in the first of the 50 columns rather than the last, as I have proposed above.

How to use ARRAYFORMULA with OFFSET to previous row without getting circular reference error

Example sheet: https://docs.google.com/spreadsheets/d/14ma-y3esh1S_EkzHpFBvLb0GzDZZiDsSVXFktH3Rr_E/edit?usp=sharing
In column B of ItemData sheet, I have achieved the result I want by copying the formula into every cell in the column, but I want to solve this using ArrayFormula instead.
In column C I have achieved the same result using ArrayFormula. However, for addition, column C is referring to cells in column B, while column B is referring to cells in column B. I.e. every cell in column B is adding 1 to the cell on the row above.
If I select the C3 formula text and paste it into the cell edit field for cell B3 (to not screw up cell references during copy - I know I could make them static references, but this is not my problem), the cell gets an error value of
#REF!
Error
Circular dependency detected. To resolve with iterative calculation, see File > Spreadsheet Settings.
Do note that the additions that need to be done are the same in both cases: Add 1 to the value of the cell on the previous row, so there is no circular reference involved. There is a starting value provided in B2, and cells in B3 and downwards should use the data from the B cell in the previous row.
Also, note that I did try File->Spreadsheet settings and enabling circular reference computation with max 25 items, but this only fills in the first two cells (B3 and B4).
How can I solve this problem? I would prefer having something like ArrayFormula, where the formula only exists in a single cell. But copy-pasting would be acceptable as long as any new rows, inserted in between or added at the bottom, would get the same formula added in column B.
Will matching items always be consecutive? It seems that way since you're comparing each Item cell to the cell above it right in your formula logic. That breaks an [unwritten?] rule of spreadsheet normalization; values' addresses themselves generally should not be treated as data.
IF you're committed to it though, have you considered explicitly using location as a data source? Example:
=ARRAYFORMULA(IFS(
NOT(LEN(A3:A40)),,
ROW(A3:A40)-3-MATCH(A3:A40,A$3:A$40,0)<=VLOOKUP(VLOOKUP(A3:A40,Items!$A$2:$D,2,false),DataPerColor!$A$2:$B,2,false),ROW(A3:A40)-3-MATCH(A3:A40,A$3:A$40,0),
true,
))
Just like your formulas, all that does in English is:
for each row,
if there's no Item, don't output any ItemData,
if the number that belongs in this cell¹ is less than or equal to the lookup, print it,
otherwise, don't output any ItemData
But then what is ¹ "the number that belongs in this cell" and how can we calculate it without using column B? I abuse locations of things to get it. Looking down your row B, each number that appears is just:
this row's number,  minus  
the row where items start [always 3],  minus  
the row number [in just the Item rows] of the first row containing this row's Item
Using the second-to-last ItemC as an example: the first ItemC is the 16th item listing, and the one we're looking up… the "second-to-last ItemC" is in row 21 of the sheet. 21-3-16 = 2 …the number you wanted.
If you can stomach that, it's a single formula and does work according to your specifications.

Stop google array formula from expanding sheet to 50,000 rows

I've got an array formula which I've managed to put together as this:
=ARRAYFORMULA(if(row(B:B)=1,"Status",(if(D:D="","",IF(D:D<today(),CONCAT("Overdue by ",(TODAY()-D:D) & " days"),IF(D:D<TODAY()+30,CONCAT("Due in ",(TODAY()-D:D) & " days"),if(D:D>today(),"Not Due","")))))))
For some reason it expands the sheet much larger than I need it with blank cells. I only need it to a max of 500. Any ideas how I'd stop this from happening?
In extremis you might wrap your formula in ARRAY_CONSTRAIN and predefine the maximum number of rows and columns:
=array_constrain(ARRAYFORMULA(if(row(B:B)=1,"Status",(if(D:D="","",IF(D:D<today(),CONCAT("Overdue by ",(TODAY()-D:D) & " days"),IF(D:D<TODAY()+30,CONCAT("Due in ",(TODAY()-D:D) & " days"),if(D:D>today(),"Not Due",""))))))),500,1)
Late with the answer, but I've noticed that ArrayFormula starts expanding sheet only if the formula is not in the same row as the first cell you're targeting, so in your case B:B - ArrayFormula should be placed in first row, for B2:B - it should be placed in the second row.
Note: this behaviour only applies to to ArrayFormulas that store nested functions such as IF statements.
Thank you for the pointers in this thread. I had an arrayformula that started:
=arrayformula(if(A3:A="","",[do stuff()]))
The formula created 50,000 rows which slowed everything to a crawl.
I edited it to constrain the array to 996 rows thusly:
=arrayformula(if(A3:A999="","",[do stuff()]))
All was well and the sheet was fast as lightning again
You probably have that formula in more than one cell, and it seems it should only be in the first row of whichever column you want it to be in.

Resources