Google Sheets: using index() to automatically populate the formula - google-sheets

I have this sheet:
I sum the value of A, B, C and put the result in column F. I use simple formula :
=A1+B1+C1
But rather than doing the copy/paste the formula to F2 - F5, I modify the formula using index() to populate the formula:
=index(A1:A5+B1:B5+C1:C5)
This will automatically calculate all the 5 rows. But now i want to use sum():
=sum(A1:C1)
Does anyone know how to use index() like the previous formula to automatically count for each of row?
Thanks,
Andi

SUM is not supported under ARRAYFORMULA / INDEX so you need to use MMULT:
=INDEX(MMULT(A1:C3, SEQUENCE(COLUMNS(A:C))^0))

I am not 100% sure I understand your question. But, you can enter an array formula once and it will automatically fill in formulas below. So change this:
=sum(A1:C1)
to this:
=ARRAYFORMULA(A1:A + B1:B + C1:C)

Related

If a column has a value (numeric or text) then show it's corresponding cells in another spreadsheet

I have 2 spreadsheets, in the first spreadsheet, in column E, if there is any value present ( whether numeric or text then show its corresponding cells ( i.e only name and ID) in another spreadsheet.
Sheet 1:
Desired Output in spreadsheet 2:
Thank you
You need FILTER() function. Try-
=FILTER(Sheet1!A2:D,Sheet1!D2:D<>"")
Or QUERY() function like-
=QUERY(Sheet1!A:D,"where D is not null",1)
For the ideal output, you may try:
=filter({'Sheet 1'!D:D,'Sheet 1'!A:A ,'Sheet 1'!E:E},'Sheet 1'!E:E<>"")

Sum every n columns starting at the 1st column in the range

In Excel/Google Sheets I have found how to sum every N columns on websites such as https://exceljet.net/formula/fixed-value-every-n-columns, but the problem is, from what I can see is that it starts at N column each time. I need something that starts from column 1 and then counts every N columns. like the following:
I need to do this with a formula and not a script.
With Google-Sheets, try:
Formula in M2:
=SUM(QUERY(TRANSPOSE(A2:J2),"Skipping "&L2))
Or, a single dynamic array formula (without dragging):
=INDEX(MMULT(A2:J4*(MOD(COLUMN(A2:J4),L2:L4)=1),SEQUENCE(10,1,1,0)))
Or, more dynamic:
=INDEX(MMULT(A2:J4*(MOD(COLUMN(A2:J4),L2:L4)=1),SEQUENCE(COLUMNS(A2:J4),1,1,0)))
Note: The latter would also work in Excel with slight modifications.
Google sheets formula:
=SUM(FILTER(A2:J2, MOD(A2:J2, L2)=1))
then drag to other cells
or use this array version:
Array version:
=INDEX(TRANSPOSE(MMULT(A2:J4,TRANSPOSE(COLUMN(A2:J4)^0 *
N(MOD(COLUMN(A2:J4), L2:L4)=1)))), ,1)
If you want the cells that were added to be automatically highlighted.
Conditional formatting used on A2:J:
=MOD(COLUMN(), $L2)=1
In M2:
=SUMPRODUCT(A2:J2,N(MOD(SEQUENCE(,COLUMNS(A2:J2),0),L2)=0))
and copied down.
Try this formula on column M:
=SUM((sumif(ArrayFormula(mod((COLUMN(B2:J2)-COLUMN(B2)+1),L2)),0,B2:J2))+A2)
Here's the result on Column M.
Just to break down the code sumif(ArrayFormula(mod((COLUMN(B2:J2)-COLUMN(B2)+1),L2)),0,B2:J2) does the actual calculation with the number of intervals set on Column L but take note that I started at the 2nd column so the range here does not include the first column. The result from this is at the Column O highlighted red as you can see in the screenshot.
At the Column M is the actual solution where I only added the first column by using SUM on top of the previous formula.
I hope my explanation is clear.
Just copy/drag the formula down to each row and it should work.
Reference: How to Sum Every Nth Row or Column in Google Sheets Using SUMIF

Iterable Sum over row in google sheets?

I have data in google sheets, looking like this:
A
B
C
D
E
F
G
TP
14656
18885
14317
19312
13303
14311
FN
12216
20107
14066
16323
11180
3478
and I want to implement the following formula:
which would manually look like this:
=(B1/(B1+B2))+(C1/(C1+C2))+...+(G1/(G1/G2))
However, I need this formula to be scalable. I've tried to use ARRAYFORMULA and SERIESSUM but could not manage to actually iterate over the row. Does sheets even support this, and if so, how does sheets implement iterating sums?
You can do the following:
=Sum(ArrayFormula(B1:G1/(B1:G1+B2:G2)))
Update:
If you want the range to be dependent on a manually entered j, use:
=Sum(ArrayFormula(Indirect("R1C2:"&"R1C"&j+1,0)/(Indirect("R1C2:"&"R1C"&j+1,0)+Indirect("R2C2:"&"R2C"&j+1,0))))
This assumes that the table in your post starts in A1 (R1C1).

Google Sheet how to concat and calculate

I have created a sheet that generate random math questions. I'm having issue create automated answers.
google sheet concat not working
issue example 2
How do I get the result in F6? In another word, how do I get 111 in F6 instead of the math 30+81"?
If you want to get the sum of the two numbers you must use the SUM() formula in the cell you want it to get the result.
The SUM() formula is used as follows:
=SUM(number_1,number_2,number_3...)
In your case the formula would be:
=SUM(B6,D6)
After your comment:
You can use the IFS formula, its a bit tricky but it would work.
The syntaxis is this:
IFS(condition1, value1, condition2, value2, …)
To do what you want you should implement something like this:
=IFS(C6="-"; B6-D6; C6="+"; B6+D6;C6="/"; B6/D6; C6="*"; B6*D6)
This formula will check the cell operator and depending on it will perform one action or another.
You may try QUERY() function with a helper column, like this-
=query(,"Select "&D1&" label "&D1&" ''",0)
Alternatively, without a helper column, the formula would be-
=query(,"Select "&A1&B1&C1&" label "&A1&B1&C1&" ''",0)

How to create arrayformula sequence number separated by comma in google sheets

How to create arrayformula sequence number separated by comma in google spreadsheets
expected results is in column B
A
B
5
1,2,3,4,5
2
1,2
3
1,2,3
How about the following sample formula?
Sample formula:
=JOIN(",",ARRAYFORMULA(ROW(INDIRECT("A1:A"&A1))))
When you use this formula, please put this to a cell "B1" and drag down it.
The flow of this formula is as follows.
Create a1Notation of cells using "A1:A"&A1 using INDIRECT.
Retrieve row numbers from the a1Notation using ROW.
Join the row numbers with , using JOIN.
Result:
Note:
When you want to put all result values using one formula, unfortunately, I couldn't find the formula using the built-in functions. In that case, I would like to propose to a custom function as follows. When you use this, please copy and paste the following script to the script editor of Spreadsheet.
And, please put a formula of =SAMPLE(A1:A) to a cell "B1". By this, the result values are put to the column "B" using the values of column "A".
const SAMPLE = v => v.map(([e]) => e && !isNaN(e) ? [...Array(e)].map((_, i) => i + 1).join(",") : "");
References:
INDIRECT
ROW
JOIN
Custom Functions in Google Sheets
You can use TEXTJOIN() with SEQUENCE() function.
=TEXTJOIN(",",TRUE,SEQUENCE(A1))
You can also use this functions in desktop Excel365

Resources