This may be far more simple than I think. What I'm trying to do is use the ArrayFormula to copy an existing formula to all the rows in a particular column.
To begin with, I have several columns along the lines of:
What I'm doing is adding the first three numbers and multiplying them by the fourth. I also have an IF condition in which, if the fourth column is blank, I leave the value in column 5 blank.
Now, I'm trying to convert this to an ArrayFormula to repeat this for all the rows in column 5.
So I went from:
=IF(ISBLANK(E2)=TRUE,,SUM((B2+C2+D2)*E2))
to this:
=ArrayFormula(IF(ISBLANK(E2:E)=TRUE,,SUM((B2+C2+D2)*E2)))
But what this does is, when I add a new row, ALL of the values in column 5 are set to the same value. Here is an example:
So, my first thought was to set the range on the SUM formula and change it to:
=ArrayFormula(IF(ISBLANK(E2:E)=TRUE,,SUM((B2:B+C2:C+D2:C)*E2:E)))
But that just makes all the values to sum of all of what the individual values should be...so, in my example, it works out to 435 (60 + 135 + 240).
What am I doing wrong here? The values in column 5 should be different in each row (e.g., row 2 should be 135 and row 3 should be 240).
Thanks!
use:
=ARRAYFORMULA(IF(ISBLANK(E2:E)=TRUE,, (B2:B+C2:C+D2:D)*E2:E))
SUM is not supported under AF
Related
I am trying to figure out how to split the range in google sheets by
"-" delimiter and add the result. Basically from the image below, I am trying to split on "-" and add up the ones (i.e 1 + 1 +1 +1 = 4). However, using the formula below it adds up all of the numbers (i.e 1 + 5 +1 + 1+1 + 0 +1 +3 = 13) which is not what I want
You are correctly splitting the values into to two columns of data, but then summing the entire dataset. You need to specify your summation to just the column you want (which appears to be the first column). Index function will do this probably the best as the second parameter can specify which column in a data set.
Summing the first column:
=sum(index(split(B11:B14,"-"),,1))
Summing the second column:
=sum(index(split(B11:B14,"-"),,2))
Showing all (same as your your arraysformula split)
=index(split(B11:B14,"-"))
See sample sheet here.
In my Google Sheet, I have 1000+ rows of Date entries. For each Date, I am calculating the Month# and Week# using MONTH() and WEEKDAY() functions respectively.
Here is the link to a sample file: https://docs.google.com/spreadsheets/d/1Af5-pYMFWZ1QtLoaAbPZYMGRvk43JBslUp4KyOFADfA/edit?usp=sharing
Problem Statement:
For all rows which have a unique Month# and Week#, I would like to implement a formula and calculate Output. For example, in my sheet, rows 3 to 6 pertain to Month=1 and Week=4. For this set of 5 rows I am calculating Output column as the subtraction from the first element in that set (ie... C3-$C$3, C4-$C$3, C5-$C$3 so on ). Similarly row 7 to 10 pertain to Month=1 and Week=5, and so I calculate Output
as Data-$C$7 and so on.
How do I implement this structure to calculate Output column on each set of unique Month# and Week# values?
Delete everything from Column F (including the F2 header). Then place the following formula into cell F2:
=ArrayFormula({"Output";IF(C3:C="",,IFERROR(C3:C-VLOOKUP(E3:E,{E3:E,C3:C},2,FALSE)))})
This one formula will create the header and return results for all valid rows.
Since VLOOKUP always finds only the first matching instance of what it is looking up, we can use it to ask that each value in C3:C subtract that first instance of where week-number match for each row.
By the way, although you didn't ask about this, you can also use this type of array formula in Columns D and E, instead of all of the individual formulas you have. To do that, delete everything from Columns D and E (including the headers). Then...
Place the following formula in D2:
=ArrayFormula({"Month #";IF(B3:B="",,MONTH(B3:B))})
... and the following formula in E2:
=ArrayFormula({"Week #";IF(B3:B="",,WEEKNUM(B3:B))})
I am using the following formula to calculate a Total row that calculates averages for percentages in the columns. However, since the data contains some empty values, the averages calculated is not correct.
={"TOTAL",arrayformula(transpose(query(transpose(query({(B16:M19)},"Select " & TEXTJOIN(",",true,arrayformula(if(filter($B$15:15,$B$15:15<>false),"Sum(Col" & Column($B$15:$M$15) - Column(B$15) + 1 & ")/Count(Col" & Column($B$15:$M$15) - Column(B$15) + 1 & ")"))))),"select Col2 format Col2 '0.00%'",)*100%))}
Ocassionally, I also get errors in my production spreadsheet viz.,
Unable to parse query string for Function QUERY parameter 2: AVG_SUM_ONLY_NUMERIC
or
Unable to parse query string for Function QUERY parameter 2: TypeError: Cannot read property 'get' of undefined
These go away if i coerce the range like this:
(B16:M19)+0 .... or.... N(B16:M19)
But this results in the average calculated incorrectly as the average considers the 0's that get replaced or the empty cells now. How can this be avoided and the values calculated correctly?
P.S: i had to hardcode the range as i don't know how to make this formula more dynamic. If anyone has an idea, please do share with me.
Here is the sample sheet. FTR Table
I came up with this formula, for your total values. See B23 in your Tables sheet:
=IFERROR(SUM(B16:B19)/COUNT(FILTER(B16:B19,B16:B19>0)),0)
If this tests out okay for you, I can try to see if it can be developed as an arrayformula.
It just sums each column in the table, and divides that by the count of values in the table that are greater than zero, so it excludes both blanks and zeroes in the table.
I just wanted a simple way to number columns or rows in a Google Sheet, and most answers I've found offer many options that are far more complicated than I needed them to be.
Example: I want to number every column in the active sheet, starting with 1 for Column A and counting up by 1, regardless of the content of any other cells on the sheet and if I add columns to the sheet later, I want them to automatically update with the correct column numbers.
Another way is to use SEQUENCE.
So putting =SEQUENCE(99) in A1 would number the first 99 rows, from 1 to 99.
To number columns, just rotate that array, with TRANSPOSE.
So if A1 held =TRANSPOSE(SEQUENCE(26))
that would number columns A to Z with the numbers 1 to 26.
If you want to number both columns and rows,try:
in A1: =SEQUENCE(999), and
in B1: =TRANSPOSE(SEQUENCE(25,1,2))
I realise that this is numbering a specific number of rows, or columns, but I often find that very useful. You could modify this to number all columns or rows by adding some count to determine the total number of rows or columns, and using that in place of the first parameter for the SEQUENCE function.
The simplest way I've found to do this is by putting either of the following formulas in A1:
For numbering rows: =ArrayFormula(ROW(A:A))
And for columns: =ArrayFormula(COLUMN(1:1))
After putting the formula in A1, I'll usually hide the column or row the formula is in so I don't accidentally change or delete it.
If I want the counting to start at 1 on the 2nd, 3rd, or 4th row or column, then adding a -1,-2, or -3 respectively to the end of the formula gets that done.
For example: To number columns starting with 1 in Column C, the formula I put in A1 is =ArrayFormula(COLUMN(1:1)-2).
This may be way more basic than most people on this site are generally looking for, but for some reason it took me an unexpectedly long time to find it/ figure it out, so I thought maybe someone else would find it useful in the future.
I'm new to Sheets and I don't know any terminology yet so I wasn't sure how to look this up.
If I have:
A1[=SUM(B1:1)]
How do I automatically copy that to A2 so that:
A2[=SUM(B2:2)]
And the same thing continues either indefinitely or until I declare a stopping point?
First of all, if you simply copy-paste the formula from A1 to A2 (or several cells below), it will automatically change as you want. This is how relative references work.
But it's also possible to get all the sums with one formula.
The following formula, entered in A1, will create sums of the first seven row in column A. To change the number of rows summed, replace 7 in B1:7 with another number.
=arrayformula(mmult(B1:7 + 0, transpose(B1:1 * 0 + 1)))
Explanation:
B1:7 + 0 coerces the entries to numbers (so that blank cells become 0).
transpose(B1:1 * 0 + 1) creates a column vector of 1s of suitable size.
matrix multiplication mmult by a column of 1s amounts to summing each row.
the wrapper arrayformula indicates that the operations are to be done on arrays.