I'd like to insert time windows repeatedly in a column, like this:
10:00-10:20
10:20-10:40
10:40-11:00
11:00-11:20
11:20-11:40
12:00-12:20
Is there a way to achieve this?
Put data in cells:
B1 = 10:00 (start time)
B2 = 12:20 (end time)
B3 = 20 (interval in minutes)
Here's single arrayFormula, that will generate your column:
=ARRAYFORMULA(TEXT(B1+B3*1/24/60*(row(OFFSET(B8,,,(B2-B1)/(B3*1/24/60)))-row(B7)-1),"HH:MM")&"-"&TEXT(B1+B3*1/24/60*(row(OFFSET(B8,,,(B2-B1)/(B3*1/24/60)))-row(B7)),"HH:MM"))
Explanations
Look at sample file to explore more about this formula. Pay attention on some details:
any kind of logical sequence could be done with help of series 1,2,3... Formula like =ARRAYFORMULA(row(OFFSET(B8,,,7))-row(B7)) gives us column from 1 to 7.
Time treated like numbers in sheets: 1 day is 1, 1 hour is 1/24, 1 minute is 1/24/60 and so on
Time can't be properly converted into text as it's number. So you have to use text(time, "HH:MM") formula to convert time into text.
This will repeat your time window. The formula assumes the time range is in A2:A6.
The 3 in the formula is the number of repeats (change to you need). You might want
to consider placing A2:A6 on another sheet and referencing it in the formula.
=TRANSPOSE(SPLIT(JOIN(",", ARRAYFORMULA(SPLIT(transpose(rept(join(",",A2:A6)&",",3)),",")&",")), ","))
Related
I have the below formula which in theory should work but it adds in additional numbers giving an incorrect figure.
=SUMIFS(Sheet1!F3:F, Sheet1!B3:B, "<="&TODAY()-3, Sheet1!B3:B, ">="&TODAY()-10)
My dates (yyyy-mm-dd) are in column B and my figures are in column F.
I want this to provide the total sales figure for a rolling 7 days but to have a 3 day delay.
I have attached my example workbook: https://docs.google.com/spreadsheets/d/1koU28NWl9T0D2Pip0caa1tWXrAeQFHtjgEz1a1kngvI/edit?usp=sharing
your formula should be:
=SUMIFS(Sheet1!F2:F, Sheet1!B2:B, "<="&TODAY()-3, Sheet1!B2:B, ">="&TODAY()-9)
&
=AVERAGEIFS(Sheet1!F6:F, Sheet1!B6:B, "<="&TODAY()-3, Sheet1!B6:B, ">="&TODAY()-9)
you can test the output with filter like:
=FILTER(Sheet1!B2:F, Sheet1!B2:B<=TODAY()-3, Sheet1!B2:B>=TODAY()-9)
I have managed to make this formula:
=IF(COUNTIF($A$1:A1,A1)=$B$1,A1+1,A1)
Is making an incremental list in the same column, starting with 01, and on cell B1 I am instructing how many times this number should repeat (up to 5 times per number). So, if I say repeat 2 times it looks like this:
Column A
1
1
2
2
How can I make it an Array Formula? I'm barely starting on Arrays so I'm just trying to learn as I go.
you can try to solve this with the following formula =ArrayFormula(flatten(if(SEQUENCE(1,C1),SEQUENCE(C2)))) but you should specify the value limit in cell C2 to which the numbers must increase, otherwise the formula will loop
Try this
=ARRAY_CONSTRAIN(arrayformula(query(flatten(split(rept("|"&A2:A,B2:B),"|")),"select * where Col1 is not null")),SUM(B2:B),1)
https://docs.google.com/spreadsheets/d/1qXy-hzWUnsUmAa-8aV5IHOyZABGD_h8ajICLwdyNge8/edit?usp=sharing
Try Sequence() with ROUNDUP() function.
=ArrayFormula(ROUNDUP(SEQUENCE(B1*B1)/B1,0))
When enter 3:
I have a google sheet that gives me a dynamic day increment. The formula I am using right now is this:
=IF(ISTEXT(A1),1,IF(WEEKDAY(B2)=7,,IF(WEEKDAY(B2)=1,,INDEX(FILTER($A$1:A2,$A$1:A2<>""),COUNT(FILTER($A$1:A2,$A$1:A2<>"")))+1)))
The first part (ISTEXT) checks the cell above to see if it has text...which happens to be the column header. If it does, we start the count at 1. After that, it will increment +1 as long as the date in column B is not a weekend (Saturday or Sunday). If it is, it will leave it blank. Then once it hits Monday again, it continues the count where it left off.
This gives me a dynamic way to count out a 20 work day schedule. I can plug in the start date and it will count out a 20 day work day schedule, skipping weekends. I am trying to add an additional mechanism to incorporate other interruptions to the work day schedule, such as holidays. I have a column (F) that I place notes in. I would like to have something like this incorporated in the original formula:
=if(F2="Holiday","H",<do the other stuff>)
Problem I am having is that everything I did in this original formula is based on empty spaces. Once an H gets placed in the field, it breaks the incrementing. I am thinking maybe I am overcomplicating this or doing something wrong, but hopefully someone can help me out here.
Example: Google Sheets
I duplicated the sheet (see tab JPV_HELP) and entered in B3
=sequence(eomonth(B2, 0)-B2, 1, B2+1, 1)
and in A2
=Arrayformula(if(C2:C<>"", regexreplace(C2:C, "[^A-Z]",), if( (weekday(B2:B) = 1)+(weekday(B2:B) = 7), ,countifs (weekday(B2:B), ">1", weekday(B2:B), "<7", C2:C, "", row(B2:B), "<="&row(B2:B)))))
If anything is entered in column C, the formula will extract the capital letters to output in column A.
See if that works for you?
Often I want to quick fill of a list of time similar to how I put a 1 in A1 and then in A2 I place A1 + 1 to get two and then I copy that down the next 100 cells to get from 1 to 100. I want to do the same thing with time. It also gives me the advantage of change the first cell and updating all the times. I asked this partly because the other answers are more complex and never get to a simple solution for this kind of process that is so often used.
to populate rows with numbers from 1 to 100 use:
=SEQUENCE(100)
to get time intervals use:
=INDEX(TEXT(SEQUENCE(12, 1, 0, 2)*"1:00:00", "hh:mm:ss"))
=INDEX(TEXT(SEQUENCE(
12 +N("number of rows"),
1 +N("number of columns"),
0 +N("start from midnight"),
2 +N("interval of increase"))
*"1:00:00" +N("period of increase"),
"hh:mm:s" &N("time format")))
Working through https://spreadsheetpoint.com/add-time-in-google-sheets/ I came up with:
Make sure the cells you are working with are in the time format you desire.
Place the time you want to start with in the first cell, let's say A1
To add an hour to the time in A1, use =A1+60/(24*60), let's say in A2
Now you can copy A2 down as far in column A you desire to get the time.
Notice, the 60 in the formula =A1+60/(24*60) is the number of minutes. Hence, if you want to do a half-hour, you can use 30.
I'm using Google sheets for data entry that auto-populates data from my website whenever someone submits to a form. The user's data imports into my sheet with a timestamp (column A).
Using the Arrayformula function, I'd like a column to autofill all the dates of a timestamp within that month. For example, if 1/5/2016 is entered as a timestamp, I'd like the formula to autofill in the dates 1/1/2016 - 1/31/2016.
Additionally, I'd like other months added in the Arrayformula column. For example, if both 1/5/2016 and 2/3/2016 are entered in column A, I'd like the formula to fill in the dates from 1/1/2016 - 2/29/2016.
I know I can manually write in the dates and drag them down the column, but I have a lot of sheets, and using an Arrayformula will save me a lot of time. I've tried a similar formula in column B, but it doesn't autofill in the date gaps. Is what I'm looking for possible?
Here's a copy of the editable spreadsheet I'm referring to: https://docs.google.com/a/flyingfx.com/spreadsheets/d/1Ka3cZfeXlIKfNzXwNCOWV15o74Bqp-4zaj_twC3v1KA/edit?usp=sharing
Short answer
Cell A1
1/1/2016
Cell A2
=ArrayFormula(ADD(A1,row(INDIRECT("A1:A"&30))))
Explanation
In Google Sheets dates are serialized numbers where integers are days and fractions are hours, minutes and so on. Once to have this in mind, the next is to find a useful construct.
INDIRECT(reference_string,use_A1_notation) is used to calculate a range of the desired size by given the height as a hardcoded constant, in this case 30. You should not worry about circular references in this construct.
ROW(reference) returns an array of consecutive numbers.
A1 is the starting date.
ADD(value1,value2). It's the same as using +. As the first argument is a scalar value and second argument is an array of values, it returns an array of the same size of the second argument.
ArrayFormula(array_formula) displays the values returned by array_formula
As A1 is a date, by default the returned values will be formatted as date too.
Increment by Month
If anyone wants to be able to increment by month, here's a way I've been able to accomplish that. Your solution #ptim got me on the right track, thanks.
Formula
Placed in B1
First_Month = 2020-11-01 [named range]
=ARRAYFORMULA(
IF(
ROW(A:A) = 1,
"Date",
IF(
LEN(A:A),
EDATE( First_Month, ROW( A:A ) -2 ),
""
)
)
)
Result
ID Month
1 2020-11-01
2 2020-12-01
3 2021-01-01
4 2021-02-01
5 2021-03-01
I have an alternative to the above, which allows you to edit only the first row, then add protection (as I like to do with the entire first row where I use this approach for other formulas):
=ARRAYFORMULA(
IF(
ROW(A1:A) = 1,
"Date",
IF(
ROW(A1:A) = 2,
DATE(2020, 1, 1),
DATE(2020, 1, 1) + (ROW(A1:A) - 2)
)
)
)
// pseudo code!
const START_DATE = 2020-01-01
if (currentRow == 1)
print "Date"
else if (currentRow == 2)
print START_DATE
else
print START_DATE + (currentRow - 2)
Notes:
the initial date is hard-coded (ensure that the two instances match!)
ROW(A1:1) returns the current row number, so the first if statement evaluates as "if this is Row 1, then render Date"
"if this is row 2, render the hard-coded date"
(nB: adding an integer to a date adds a day)
"else increment the date in A2 by the (adjusted) number of rows" (the minus two accounts for the two rows handled by the first two ifs (A1 and A2). Eg: in row 3, we want to add 1 to the date in row 2, so current:3 - 2 = 1.
Here's a live example (I added conditional formatting to even months to assist sanity checking that the last day of month is correct):
https://docs.google.com/spreadsheets/d/1seS00_w6kTazSNtrxTrGzuqzDpeG1VtFCKpiT_5C8QI/view#gid=0
Also - I find the following VScode extension handy for syntax highlighting Google Sheets formulas: https://github.com/leonidasIIV/vsc_sheets_formula_extension
The Row1 header trick is courtesy of Randy via https://www.tillerhq.com/what-are-your-favorite-google-spreadsheet-party-tricks/
nice. thanks.
To get the list length to adapt to the number of days in the selected month simply replace the static 30 by eomonth(A1;0)-A1. This accommodates for months with 31 days, and for February which can have either 28 or 29 days.
=ArrayFormula(ADD(A1,row(INDIRECT("A1:A"&eomonth(A1;0)-A1))))
Updated for 2022:
This can now be done pretty easily with the SEQUENCE function, it's also a bit more adaptable.
Below will list all of the days in columns but you can swap the first 2 values to place in rows instead:
=SEQUENCE(1,7,today()-7,1)
More specific to your example, below will take the date entered (via cell, formula, or named cell) and give you the full month in columns:
=SEQUENCE(1,day(EOMONTH("2016-1-5",0)),EOMONTH("2016-1-5",-1)+1,1)