How to repeat a value specified number of times in Google Sheets - google-sheets

How to repeat a value specified number of times in Google Sheets, assuming no overlap or ignoring overlap if any.
Screenshot of the example with ID in column B and Nights in column C.
Trying to reach desired output (column D) with reservation ID repeated the specified number of nights.
Link to example

Your sheet is "Comment only." But try deleting everything from Col D (including the header) and placing the following formula into cell D1:
=ArrayFormula({"ID Full Stay"; IF(A2:A="",,IF(ROW(A2:A)>(VLOOKUP(ROW(A2:A),FILTER(ROW(C2:C),C2:C<>""),1,TRUE) + VLOOKUP(ROW(A2:A),FILTER({ROW(C2:C),C2:C-1},C2:C<>""),2,TRUE)),,VLOOKUP(ROW(A2:A),FILTER({ROW(C2:C),B2:B},C2:C<>""),2,TRUE)))})
This one formula will produce the header (which you can change as you like within the formula itself) and all results for all rows.

Related

Query importrange HUGE multiple sheets and turns out error

so I have 5 separate google sheets, each one with the same title and format enter image description here.
There are 8000-10000 rows each so far, as it's a daily sales updating data, yearly may finish with 20000-40000 rows each.
So what I want to do is to merge all of them into another single sheet, and I've tried the following formulas:
enter image description here
Formula A
={IMPORTRANGE(B2,C2);IMPORTRANGE(B3,C3);IMPORTRANGE(B4,C4);IMPORTRANGE(B5,C5);IMPORTRANGE(B6,C6)}
Results:
#VALUE!
"In ARRAY_LITERAL, an Array Literal was missing values for one or more rows."
Formula B (reduced the data to only one month)
=QUERY({IMPORTRANGE(B2,C2);IMPORTRANGE(B3,C3);IMPORTRANGE(B4,C4);IMPORTRANGE(B5,C5);IMPORTRANGE(B6,C6)},"SELECT * Where Col2 > DATE'2022-5-1' AND Col2 <= DATE'2022-5-31' ",0)
Result:
#VALUE!
"In ARRAY_LITERAL, an Array Literal was missing values for one or more rows."
Formula C (check if is the problem of the code)
={IMPORTRANGE(B2,C2);IMPORTRANGE(B3,C3)}
Results:
It works.
So my question is that, there is anyway via google sheet let me merge all the 5 sheets in one (5sheets*40000rows into one sheet) , or it's not the place to manage that volumn of data?
every importrange needs to be run separately before you use it in your joint formula. the array error you are getting is a result of some importranges importing those 7 columns and those importranges that are not connected output one single cell. make sure you allow access to all your importranges.

Implement formula in a column based on contents of each cell

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))})

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

Google sheets: inter-sheet formula seems to ignore MATCH criteria... (Copy data from one sheet to another using 1 Match criteria)

I have a Google spreadsheet with 5 tabs (sheets) and I want to copy rows of data from one sheet to another, IF a criteria matches in one of the sheet.
Sheet1 has hundreds of rows of data, across numerous columns. One of the columns lists dates. That column is mostly set to Date format. That date col also uses various Conditional Formatting rules. (I cannot change these or the formatting of this column!).
In sheet5 I have a formula that is supposed to look at sheet1 and find all the rows with a certain date in the date col and then copy the data in that row to a row in sheet5.
It looks like this: =INDEX(sheet1!$A1:$O2002,MATCH($B$1,sheet1!$Q:$Q,0),0)
It kind of works... if I just paste the formula in one cell in sheet5, it finds a row matching the date criteria and copies data over. But if I want to query more of sheet1, by dragging the cell down and find more rows of data to copy over... it just copies all the rows from sheet1 after the initial find... completely ignoring what it's comparing in $B$1 to $Q:$Q... I suspect that what I think it's comparing in MATCH($B$1,sheet1!$Q:$Q,0) may not be what's actually happening, hence the result not matching my expectations...
Here is a screen capture of the sheet I want to copy data from: This sheet is set up and controlled by another party. I CANNOT change data; I CANNOT change data format that is already entered (eg I can't change a col set to Date to Plain Text!) See red notes.
But I can convert Dates in col N to Plain Text in col Q. Column Q is what I am querying/comparing in the formula in the destination sheet (see second screen capture below)
Sheet1 capture: data to copy, criteria date col
In sheet5 I have this formula that queries sheet1:
=INDEX(sheet1!$A1:$O2002,MATCH($B$1,sheet1!$Q:$Q,0),0)
Here is a screenshot of what that formula produces in sheet5
Sheet5 capture: result of using formula
Notice, it kind of works...(when I just paste the formula into my starting cell... it found the one line with the criteria I set) but then if I drag B3 down to query sheet1 more... it just grabs everything, even if $Q:$Q doesn't match the criteria set in B1...
Why?
Any help or clarifying questions are appreciated. Thanks
when dragging you did not lock the rows with $
your formula:
=INDEX(Sheet1!$A1:$Q100, MATCH($B$1, Sheet1!$Q:$Q, 0), 0)
should be:
=INDEX(Sheet1!A$1:Q$100, MATCH($B$1, Sheet1!Q:Q, 0))
coz with your initial formula you just created sort of a "sliding range" by every drag-down. to understand the formula... you are indexing range A1:A100 (from row 1 to row 100) where you narrow it down to just 13th row (MATCH outputs row 13 coz there is the match found. next you drag down and indexing range changes to A2:A101 but the MATCH formula always outputs 13 so 13th row from range A2:A101 is row 14, etc.
anyway, use this in Sheet5!B3 after you delete everything in B3:B range:
=FILTER(Sheet1!A:P, Sheet1!N:N*1=B1*1)

google sheet : generate increment number

I use this formula:
=filter(calc!B7:B,calc!P7:P="")
to display the data from Col B of 'calc' sheet where the Col P is null or "".
it works fine and it will output single column. If i want to add index number (like incremental ID number) , i normally just manually add any formula that can generate increment number and it works.
But the problem is if the number of the output of that filter() was changed , then i have to readjust the index by extending it or deleting to match the number of the output.
I'm thinking if it's possible to embed the index number (increment number) into the formula itself , for example maybe like this :
=filter({ [my_index_number] , calc!B7:B },calc!P7:P="")
so to generate 2 column, where the left is the custom index_number column. Is it possible ?
Give a try on below formula. Adjust sheet name for other sheet. I have tested the formula to same sheet.
=ArrayFormula(IFERROR(SPLIT(SEQUENCE(COUNTA(FILTER(B7:B,P7:P="")))&"#"&FILTER(B7:B,P7:P=""),"#"),""))

Resources