Output cell every nth row - google-sheets

How can I output a cell's value every nth rows
Example every 3 rows:

or you can do it with QUERY:
=QUERY(A2:A, "skipping 3")

Put this formula in A2:
=ArrayFormula(FLATTEN(SPLIT(REPT(C2:C4&"♦︎",3),"♦︎")))

use MOD:
=FILTER(A2:A, MOD(ROW(A2:A)-2, 3)=0)

Offset is relatively simple. To get an index that increases by 1 every three rows just ROUNDDOWN the ROW address by three
=OFFSET($C$2,ROUNDDOWN(ROW(A1),0)/3,0)

Related

GOOGLE SHEETS: Help needed to sum a range of cells across rows, where the range is controlled by a variable

I need to sum a range of cells across rows, but I need to be able to specify the amount with a variable.
For example.
If i write 5 in cell B1, I want to sum range A1:A5.
If i write 10 in cell B1, I want to sum range A1:A10.
If i write 20 in cell B1, I want to sum range A1:A20.
And so on.
Does anyone know a formula for this?
Kind regards.
I tried writing( in cell B1) =SUM(A1:A(1+B1)). This didn't work at all, instead a =NAME? appeared.
You may use INDIRECT to set a range by joining text, like this:
=SUM(INDIRECT("A1:A"&B1))
This formula will also work:
=SUM(BYROW(SEQUENCE(B1),LAMBDA(ROW,INDEX(A1:A,ROW))))
SEQUENCE() return an array of rows count up from 1 by default.
BYROW() can use an array as row reference and apply a LAMBDA() function to each row.
INDEX() return the CELL the matches a given INDEX of ROW and COL.
SUM sum up every value of a range (array).
also possibility:
=SUM(A1:INDEX(A:A; B1))
or:
=SUMPRODUCT(A1:INDEX(A:A; B1))

Arrayformula to return last non-empty cell in multiple rows

I need help formulating an arrayformula on how to return the last non-empty cell in a row across multiple rows.
The formula will be in column A in cell A2 and the output will look like this in column A:
The formula I have is only for 1 row. I need the formula (only 1 formula) to return the last non-empty cells of 1000+ rows.
This is the current formula I have but it's only for 1 row. I need to drag it down every time I add a new row:
=LOOKUP(1, ARRAYFORMULA(1/(B2:Z2<>"")),B2:Z2)
Is there an arrayformula that can do this across multiple rows without dragging down the formula?
any help would be appreciated. Thank you very much.
try:
=INDEX(REGEXREPLACE(TRIM(FLATTEN(QUERY(TRANSPOSE(
SUBSTITUTE(B2:Z, " ", CHAR(13))),,9^9))), ".* ", ))

Count number of line breaks in Google Sheets cell

Cell value represents a list.
Line breaks in cell represents number of items in list
Need to identify number of items in list.
Correction
The formula is incorrect for empty cells, use instead:
= LEN(A1) - LEN(SUBSTITUTE(A1, CHAR(10), "")) + 1 * COUNTA(A1)
Assuming your cell is A1
Turns out this link figured it out:
https://www.extendoffice.com/documents/excel/4785-excel-count-newlines.html
Equation where A2 is the cell you want to count the line breaks:
=LEN(A2)-LEN(SUBSTITUTE(A2,CHAR(10),""))+1

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.

Copy cell from every nth row

I'd like to grab the names in every person's name from this google spreadsheet and put it into a new column. The names will be every nth row.
Alternatively, also try:
=filter(A2:A, mod(row(A2:A)+1,3)=0)
In B2 please try:
=offset(A$1,3*(row()-1)-2,)
As the formula is copied down the offset row relative to A1 increases by three, with no column offset. In the second (starting row) 3*(2-1)-2 is 1 so the A2 value is returned. In the second output row 3*(3-1)-2 returns 4, so the A5 value is returned, and so on.

Resources