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?
Related
I ran into a problem with my Google sheet.
in the sheet Column "B" has an order date and Column "H" is counting days till today.
I want Column "H" to stop counting the day if Column"F" has a date.
Column "H" show day count till the date of column F
please see attached sample file.
Looking forward to your help
IF YOU WANT NOT TO USE YOUR FUNCTION WHEN DATE APPEARS IN COLUMN AND CONTINUE DOWN:
You should work with datevalue and iferror function (isdate does not work with arrayformula).
=ArrayFormula(
if(isblank(iferror(datevalue(B3:B23))),"your function","")
)
IF your formula is to count days passed since some date, try this:
={"Days passed";ArrayFormula(
if(isblank(iferror(datevalue(B4:B23))),today()-A4:A23,"")
)
}
IF YOU WANT THIS FORMULA TO GO FROM THE TOP AND STOP WHEN DATE APPEARS.
Core of the problem is how to check if data in this column is a date.
Then you have to use match formula to determine a row where the date is and stop arrayformula using array_constrain function.
First part (checking where is the data):
=match(FILTER(B3:B,IFERROR(DATEVALUE(B3:B))),B3:B,0)
(assuming that data is in B3:B)
We know that arrayformula should go only to 9th row of data.
So you should use =array_constrain(arrayformula(function you need);row to stop;1)
And as we have a match formula for determining a row to stop, whole formula should look like this:
=array_constrain(arrayformula(function you need);match(FILTER(B3:B,IFERROR(DATEVALUE(B3:B))),B3:B,0);1)
I have a Google Sheets document with a series of fields for every day in the year. The top row (Actually, row 2) is the Months (by full name, eg. January, February, etc.). The A column is numeric, from 1 to 31. There are several fields for each date, so the fields in the A column are merged (in other words, it's not A2, A3, A4 - more like, A2, A7, A12).
What I'd like to do is put a a hyperlink at, say, B1, that points to "today's" top field. So, today's would point to J7, and I could just click the link at B1, and get taken directly to that field.
I know this is going to involve the HYPERLINK function, but I can't figure out how to get it to work. Something like:
=HYPERLINK("#gid=0&#range=" & MATCH(TEXT(TODAY(),"MMMM"),2:2,0) & MATCH(DAY(TODAY()),A:A,1),"Click for today")
But I can't get it to work right. Any thoughts?
Assuming your months are in every column from B2:M2:
=HYPERLINK("#gid=*000000000*&range="&ADDRESS(MATCH(DAY(TODAY()),A2:A,1)+1,MONTH(TODAY())+1,4),"Click for today")
I wrote the formula so that the link could go in A1 without running into trouble, if you like. (It would also work in B1, etc.)
If there are spaces between your months, just reorder what you had so the MATCH for the row is first and wrap it in ADDRESS( row, column, 4):
=HYPERLINK("#gid=*000000000*&range="&ADDRESS(MATCH(DAY(TODAY()),A2:A,1)+1,MATCH(TEXT(TODAY(),"MMMM"),2:2,0),4),"Click for today")
(To be clear for future users, you'd need to replace the gid= number with the actual number corresponding to your sheet.)
Eric Tyler - Close. But it got me where I needed to be, so thank you so much. I was missing two key funtions: ADDRESS, and SUBSTITUTE. Here's what wound up working. (Note: In my case, the gid is 0.)
=HYPERLINK("#gid=0&#range="&SUBSTITUTE(ADDRESS(MATCH(DAY(TODAY()),A:A,1),MATCH(TEXT(TODAY(),"MMMM"),1:1,0)),"$",""),"Click here")
The ADDRESS line the way you proposed it results in the address in the format $A$1, which the HYPERLINK function doesn't like. Using that just brought be to the sheet, but not the actual cell. By using SUBSTITUTE to get rid of the $ marks, that resolved the problem.)
Thanks again!
I'm trying to make a scheduler for work and I have a dropdown list of the hours that the employees work in one column and I want it to display how many hours it is next to that. I.e.:
Column B (Selected from a drop down menu) Column C
6:00 - 14:30 to display 8 as it is an 8 hour shift
10:00 - 15:00 to display 5 as it is an 5 hour shift
Is there a way to do this?
So for the sake of clarity, I am going to develop this step by step, in several columns. These could be combined into one impenetrable formula, but that will not help you follow. You can do what I suggest here and then hide the columns with the calculation.
Suppose your time is in column A. You can do the following in the first row (mine assumes row 1, if you have headers, probably row 2) and then copy the formulas on down. In column B, I placed, =search("-",A1), which tells where the - sign is. In column C, I find the first time as a string with =left(A1,B1-2), which takes the first characters up to 2 before the dash. In column D I have =mid(A1,B1+2,5) which takes from 2 characters after the dash to the end (if it is only 4 characters long, it copies 4 not 5),and finally in column E we find the desired result, with =HOUR(timevalue(D1)-timevalue(C1)).
That does what you asked. If you wanted to add minutes you could use =MINUTE(timevalue(D1)-timevalue(C1)). Finally if a 22:00 - 6:00 graveyard shift existed, you would need to add logic for it.
You could also simplify the string calculation by in column B using the formula =split(A1,"-") and then putting =HOUR(timevalue(C1)-timevalue(B1))
And so if you really want a single formula, it could be =hour(INDEX((split(A1,"-")),2)-INDEX((split(A1,"-")),1)), which subtracts the first part from the second and converts to hours.
If in the course of time you want to handle the wrap around midnight, =iferror(hour(INDEX((split(A1,"-")),2)-INDEX((split(A1,"-")),1)),24-hour(INDEX((split(A1,"-")),1)-INDEX((split(A1,"-")),2))) should do the trick.
UPDATE: Sheets recognizes the times that resulted from the split as times. So if in B1 you place =split(A1,"-"), D1 can contain =C1-B1 if you are willing to keep the minutes. It even gives the right answer for 22:00 - 2:00.
Make a table with a column for the shifts (this could be the list used for the Validation, if you chose that method) and a column immediately to its right of the respective shift durations. I named that table Larry. Then in C2 (assuming your first dropdown is in B2):
=ArrayFormula(vlookup(B1:B,Larry,2,0))
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)
I have this planning sheet I am working on: https://docs.google.com/spreadsheets/d/1GQpZh0MOotBl_iAucGm_LnK8shIKjjgukGqaFVvGKF8/edit?usp=sharing
As you can see events are planned out on a sort of calendar look.
I will be using this every day and I would like it to highlight the current date to me automatically. I've highlighted today's date manually.
Do you see any way to do this?
It does not need to be the whole column it can just be the day number and week of day on the top if it's easier.
I would greatly appreciate any help you can give me regarding this!
Thanks a lot.
Balint
I found this question when searching for a way to highlight a whole column/row.
Here's the way to do it:
Apply to range: A1:Z1000 (this is the range of all columns/rows including the dates)
Format cells if...: [Custom formula is]
Formula (for columns): =A$1=TODAY()
Formula (for rows): =$A1=TODAY()
The dollar sign ($) will keep the reference cell fixed. So if the formula uses A$1 it takes A1, B1, C1 etc to look for the date and then highlights the entire column A, B, C etc.
If the formula uses $A1 it takes A1, A2, A3 etc to look for the date and then highlights the entire row 1, 2, 3 etc.
Just make sure that "range" covers the entire rectangle of cells and not just one date. It's easy to adapt if your dates are in a different row/column.
Hope this helps the next person who comes here with a similar problem :)
You would have to use conditional formatting
on the column with the dates. Rule should be "Date is today". Choose a color to your likings.