I have a list of dates in Column 1, which I have formatted as custom date. 1/1/2023 for example shows as Sunday 1
I need to have other cells in the table show "Weekend" if the cell in column 1 contains Saturday or Sunday
The following formula works for one of them:
=IFERROR(IFS(SEARCH("Saturday", A2), "WEEKEND"), "")
But I need it to search for both Saturday and Sunday. I've tried the following but it's not working:
=IFERROR(IFS(SEARCH("Saturday", A2), "WEEKEND"), "None",(SEARCH("Sunday", A2), "WEEKEND"), "None")
try:
=INDEX(IF(LEN(A:A),IF((WEEKDAY(A:A)=1)+(WEEKDAY(A:A)=7),"WEEKEND",),))
If you actually have text, you can use wildcards:
=IFERROR(IF(SEARCH("S*DAY",A2),"WEEKEND",),)
Also applicable for INDEX or ARRAYFORMULA
=INDEX(IFERROR(IF(SEARCH("S*DAY",A2:A),"WEEKEND",),))
Related
I am trying to build a sleep tracker in Google Sheets (link). The idea is to select a year and a month from a drop-down list in cells A1 and A2, which would then populate columns based on the number of days in that month. I have tried different formulas that I found on stack overflow and elsewhere, but could not get them to work.
In short:
I am looking for a formula that will populate the columns with days of that month and a name of the day in a row bellow.
Looking for a way to summarize the time of sleep at the end of the each day, based on a ticked checkbox.
I am not sure how the year and month selectors should be formatted (as plain number or a date).
Is there a way to automatically insert check-boxes to the days of the month?
This is the formula that I have tried to adjust:
=INDEX({TEXT(SEQUENCE(1; DAY(EOMONTH(A2&"/"&A1;0)); A2&"/"&A1; 1); {"d"; "ddd"}); {"Total"; ""}})
But it returns with "Error In ARRAY_LITERAL, an Array Literal was missing values for one or more rows."
Please note that ";" is used as an argument separator instead of "," (regional settings).
Thank you in advance!
I think that with a very small adaptation and date formatting you'll be able to easily do it. First with your selector in A2, you could set it as actual dates, but format them as mmmm:
Then, repeat the sequence in both rows starting in C2 and C3:
=SEQUENCE(1,DAY(EOMONTH(A2,0)),A2)
But formatting row 3 as ddd:
PS: yes, you can do row 3 with TEXT and INDEX. Choose your preferred one:
=INDEX(TEXT(SEQUENCE(1,DAY(EOMONTH(A2,0)),A2),"dddd"))
UPDATE with TEXT VALUES
Return to your previous A2 dropdown and try this, using MATCH to find the number of the month, and DATE to locate the correct beginning of the month in that year:
For row 2:
=SEQUENCE(1,DAY(EOMONTH(DATE(A1,MATCH(A2,{"January","February","March","April","May","June","July","September","October","November","December"},0),1),0)),
DATE(A1,MATCH(A2,{"January","February","March","April","May","June","July","September","October","November","December"},0),1))
For row 3:
=INDEX(TEXT(SEQUENCE(1,DAY(EOMONTH(DATE(A1,MATCH(A2,{"January","February","March","April","May","June","July","September","October","November","December"},0),1),0)),
DATE(A1,MATCH(A2,{"January","February","March","April","May","June","July","September","October","November","December"},0),1)),"dddd")
)
I have here formula that can easily convert the weekday text like Sunday to weekday int to 1.
=MATCH(A2,{"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"},0)
My question is how to convert array-text to array-int?
Let's say for example in a cell, I have value Sunday, Monday. Do we have a formula for us to get the array for example {1,2}?
About Let's say for example in a cell, I have value Sunday, Monday. Do we have a formula for us to get the array for example {1,2}?, I guessed that from your showing formula is used, you might have wanted 7 and 1. If my understanding is correct, when your sample formula is used, how about the following modification?
Modified formula:
=ARRAYFORMULA(MATCH(TRIM(SPLIT(A1,",")),{"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"},0))
In this case, Sunday, Monday is put in cell "A1".
Testing:
Note:
When the following formula is used,
="{"&TEXTJOIN(",",TRUE,ARRAYFORMULA(MATCH(TRIM(SPLIT(A1,",")),{"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"},0)))&"}"
When Sunday, Monday is put in the cell "A2", {7,1} is put to a cell.
you can also try:
="{"&JOIN(",",INDEX(MATCH(SPLIT(A2,", "),TEXT(SEQUENCE(7,1,2),"DDDD"),0)))&"}"
I was able to make the following gantt chart with the simple formula below, however i am having trouble adapting the formula to handle the case when the project lasts 3 months - you can see the example on row 4.
What i did was simply put a date Jul 1 2020, Aug 1, 2020, etc in row 1
and then in each row, i check the start and end against row 1 to see if its equal... if so, set the cell to true, and use conditional formatting to color it.
Now how would you check if the the row 1 date is in the range between start and end, and then set to true?
Thank you!
=ifna(
ifs(
AND(month($F2)=month(J$1), year($F2)=year(J$1)), true,
AND(month($G2)=month(J$1), year($G2)=year(J$1)), true
)
,"")
=IF(AND(
C1 >= $A2,
C1 <= $B2
),TRUE," ")
Test it here if you want: link to spreadsheet
Just test if the month in the first row falls between the dates in the first two columns. So the custom formula would be:
=and(H$1>=$F2,H$1<=$G2)
I have 1 Column with the date formatted as so "1/7/19", In the next column, I would like to check if the previous date is 7 days from Today's date. If True, I'd like to add an emoji into the second column.
I have the first column using conditional formatting which is coloring respective cells Red.
=IF(TODAY()-7<=Q3, "🔥")
=CONCATENATE(R3, "", Q3)
I plan to concatenate these two columns into a third that shows "🔥 1/7/19" if True.
try like this:
=IF(AND(A1<=TODAY(), A1>TODAY()-7), "☺ "&TEXT(A1, "M/d/yy"), )
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)