Formula based on first monday or tuesday etc of the week - excel

Is there a way to put a year into a cell (say A1), then the day of the week you want (say Monday in cell A2) and enter into the 12 cells below it the first monday of each month (or first tuesday, etc, based on whats in cell A2)?
I have been able to figure out how to do it with 1 day but I would like it to be interactive.
=DATE(2022,{1;2;3;4;5;6;7;8;9;10;11;12},7-WEEKDAY(DATE(2022,{1;2;3;4;5;6;7;8;9;10;11;12},1)-5,3))

With Office 365:
=LET(yr,A1,
wkdy,MATCH(PROPER(A2),{"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"},0),
mnt,SEQUENCE(12),
DATE(yr,mnt,1)+MOD(8-WEEKDAY(DATE(yr,mnt,1),10+wkdy),7))

You where pretty close with your formula
=DATE(A1,{1;2;3;4;5;6;7;8;9;10;11;12},7)-WEEKDAY(DATE(A1,{1;2;3;4;5;6;7;8;9;10;11;12},7),A2)
Where
A1 = year string
A2 = day of the week as number (1 = Saturday, 2 = Sunday, etc.)

Related

Excel Formula for finding if the 16th lands on a Saturday or Sunday and if it does, returning the date of the following Monday

Imagine that in cell A1 you have the first day of the month. I need a formula that finds if the 16th day of that month falls on a weekend (Saturday or Sunday) and if that is the case, return the date of the following Monday. If the 16th is not on a weekend, it will just return the date of the 16th
=If( (A1 + 15) = Saturday or Sunday, Date of the next Monday, (A1 + 15) )
I apologize in advance for my formula being terrible, I'm at a loss on this one.
For example, if A1 = "10/1/2019" then the forula will return 10/16/2019 because the 16th is not a weekend. However, is A1 = "11/1/2019" then the formula will return 11/18/2019 because the 16th is a Saturday. Thanks!
You can use the WEEKDAY function to determine the day of the week.
=IF(WEEKDAY(A1+15,2)=6,A1+17,IF(WEEKDAY(A1+15,2)=7,A1+16,A1+15))
The workday function is probably the easiest way to do this:
=WORKDAY(A1+14,1)
A1+14 --> the fifteenth of the month
We then add one workday. If that added workday falls on a Sat or Sun (or optional holiday if you want to do that), the weekend days will be skipped, otherwise the 16th will be returned.

Calculate the week number of a given date using a given a reference year

I have a formula which calculates the week number of a given date:
=WEEKNUM(Sheet2!N83)
I want a formula which returns the week number using 2018 as reference, in a similar manner as the above formula does. If the year is 2019, I want it to return weeknum + 52, so for 2019-01-01 I get week number '53'.
How can I achieve this?
This is only valid for years 2018 and 2019:
=IF(YEAR(Sheet2!N83)=2018,WEEKNUM(Sheet2!N83),WEEKNUM(Sheet2!N83)+52)
or:
=IF(YEAR(Sheet2!N83)=2018,WEEKNUM(Sheet2!N83),WEEKNUM(DATE(2018,MONTH(Sheet2!N83),DAY(Sheet2!N83)))+52)
You actually need a formula which calculates the difference in weeks.
In A1 cell, fill the first day of the reference year (e.g. 2018-01-01).
In A2 cell, put the day of the week of your interest (e.g. 2019-01-03).
In the A3 cell, use this formula to calculate the difference in weeks (in case your week begins at Mondays):
=ROUNDDOWN((DATEDIF(B1-WEEKDAY(B1-2), B2, "d") / 7), 0) + 1
Or this one (in case your week begins at Sundays):
=ROUNDDOWN((DATEDIF(B1-WEEKDAY(B1-1), B2, "d") / 7), 0) + 1

Excel : Weeknumber within month with criteria

I'm trying to make a formule to calculate the weeknumber within a week but with certain criteria. The week always starts on a monday. But if the thursday of that week is in the next month, then that weeknumber is part of the next month.
[enter image description here][2]
Right now I have the following formula:
=INTEGER((6+DAY(A4+1-WEEKDAY(A4-1)))/7) where A4 is the date.
This already calculates the weeknumber within the month, but not with the criteria of thursday. An extra added criteria is that the weeknumber should start from 6am on monday instead of at midnight. But that I can solve with an extra column to check for that.
Thanks in advance!
Consider working out the week number from the previous week number:
If it is Monday then
If following Thursday goes into the next month, reset to 1
Else increase by 1
Else use same value
So starting with a 1 in E4
=IF(WEEKDAY(A5)=2,IF(MONTH(A5+3)>MONTH(A5-4),1,E4+1),E4)
entered in E5 and copied down.
EDIT
Above works for 2017 but would need slight change to work for 2018 and onwards because month decreases from 12 to 1 across year boundary:
=IF(WEEKDAY(A5)=2,IF(MONTH(A5+3)<>MONTH(A5-4),1,E4+1),E4)
I cant upload a workbook but here is a solution:
Row 2 is headers
Row 3 is empty
B4 going down is the date(01/01/2017 up to 31/12/2017)
C4 =WEEKDAY(B4,2)
D4 =VLOOKUP($C4,$L$3:$M$9,2,0)
E4 =MONTH(B4)
F4 to J4 are empty
F5 =IF(C5=1,F4+1,F4)
G5 =IF(C5=4,11,0)
H5 =IF(MAX(E5:E11)-MIN(E5:E11)<>0,22,0)
I5 =IF(AND(C5=4,SUM(G5:G11)+SUM(H5:H11)>22),I4+1,0)
J5 =IF(H6-H5<0,1,IF(H6=22,J5,IF(OR(C6=1,I6<>0),J5+1,J5)))
L3 to M9 are vlookups
1 Monday
2 Tuesday
3 Wednesday
4 Thursday
5 Friday
6 Saturday
7 Sunday
Does that work ok for you?
In my experience most of those week number questions can be answered with some variation of your original formula - in this case this version should cater for Monday week start with the Thursday determining the month
=INT((6+DAY(B4+4-WEEKDAY(B4-1)))/7)
That works for a date in A4 but assuming you have a date/time in A4 and the week doesn't start until 06:00 on Monday then you can tweak that as follows:
=INT((6+DAY(B4+3.75-WEEKDAY(B4-1.25)))/7)

Convert year and ISO-week to date in Excel?

The year is A1=2012
The ISO-week is A2=1
As I understand it the standard way to decide to which month a week belongs is to look at in which month the Thursday occurs.
Thus, I would like to find the date of the Thursday with year A1 and ISO week A2. How can I find the date of the Thursday?
I know that this thread is related, but I can't figure this out: calculate the month from the year and week number in excel
The Thursday of week 1 will always be the first Thursday of the year, then you obviously add 7 for each week after that, so you can get the Thursday date with this formula
=DATE(A1,1,1+A2*7)-WEEKDAY(DATE(A1,1,3))
with Year in A1 and ISO week number in A2
To find the date defined by (A1,B1,C1) where A1 = ISO Year, B1 = ISO Week, and C1 = the day of the week, assuming week starts with Monday, day 1, use the following:
In VBA:
S = DateSerial(A1, 1, 3)
W = Weekday(S)
D = S - W + 7 * B1 + C1 - 6
Or in one formula in Excel:
=DATE(A1,1,3) - WEEKDAY(DATE(A1,1,3)) + 7 * B1 + C1 - 6

Using index in excel how to get a 6th value from a array

I am trying to get 6th day from the day itself and should repeat for 3 times but I am not able to get the desired output
Column A Column B(Expected output)
Sunday Sunday
Monday Friday
Tuesday Wednesday
Wednesday Monday
Thursday Saturday
Friday Thursday
Saturday Tuesday
Sunday
Wednesday
Monday
Saturday
Thursday
Tuesday
Sunday
Wednesday
Monday
Saturday
Thursday
Tuesday
Sunday
I am using:
=INDEX($E$1:$E$7,6)
and I am getting only Friday and if I do auto fill only Friday is copied to all cells.
Any assistance much appreciated.
If I understand you correctly, you want to show the name of every sixth day from a starting date. There are different approaches to that. The Index() one is a possibility, but not the easiest.
Easier: In the first cell (B1), enter the starting date. Format with custom format "dddd".
In the next cell down use a formula
=B1+5
and format with custom format "dddd". Copy down as far as desired.
OR use
=TEXT($B$1+((ROW()-1)*5),"dddd")
and copy down.
If you want to base this on today's date, you can start in B1 with
=TEXT(TODAY()+((ROW()-1)*5),"dddd")
and copy down.
EDIT: if the cell contents is not about dates and weekdays, but just any text or value, then you can use the Index() approach. For an array with seven values, you want to extract every 6th value, looping through the seven values. That would mean that the values are accessed in the following order:
1
6
4
2
7
5
3
Therfore, you need a formula that delivers this number sequence. This formula, if started in row 1 and copied down, does that:
=(1+((ROW()-1)*5))-((INT((1+((ROW()-1)*5))/7)-IF(MOD((1+((ROW()-1)*5))/7,1),0,1))*7)
Wrap an Index around it and adjust your column references. In B1 and copied down to B21:
=INDEX($A$1:$A$7,(1+((ROW()-1)*5))-((INT((1+((ROW()-1)*5))/7)-IF(MOD((1+((ROW()-1)*5))/7,1),0,1))*7))

Resources