I have a table and I have a date in cell B4 which is something like 15/03/2021
I want to count values where the start date is the value on cell B4 but also count everything till the end of that week. So everything from Monday 15/03/2021 to Sunday 21/03/2021
What I have so far is something like
=COUNTIFS(MySheet!A:A,"Y",MySheet!C:C,">="&B4)
My trouble is how to tell it "also count everything until sunday that week without having to manually put the end date into a cell
Add 6 to the value in B4 to get the second criteria.
=COUNTIFS(Mysheet!A:A,"Y",Mysheet!C:C,">="&B4, Mysheet!C:C,"<="&B4+6)
I assume the question behind your question is how to account for dates in B4 other than a monday and keep counting untill the end of that same week, therefor you can use:
=COUNTIFS(Mysheet!A:A,"Y",Mysheet!C:C,">="&B4,Mysheet!C:C,"<="&B4+7-WEEKDAY(B4,2))
This does set a Sunday as the "end" of the week as per your OP.
Your question is slightly ambiguous, so there are two possible answers
To count for exactly 7 days:
=COUNTIFS(MySheet!A:A,"Y", MySheet!C:C,">="&B4, MySheet!C:C,"<"&B4+7)
To count until the end of the next Sunday: (N.B. On Sundays, this will only count 1 day)
=COUNTIFS(MySheet!A:A,"Y", MySheet!C:C,">="&B4, MySheet!C:C,"<"&B4+8-Weekday(B4,2))
This works by saying "on or after (>=) the date given", and "before (<) 7 days later / the following Monday"
Related
How can one return the next date of a given weekday (it could be either a number 1-7 or names Sunday-Saturday).
For example, if today, on Friday 16-Oct-2009 I passed in:
Friday, it would return today's date 16-Oct-2009
Saturday returns 17-Oct-2009
Thursday returns 22-Oct-2009
Here is the Spreadsheet
I have tried this formula:
=A12+(C12+ MOD(7-day(A12),7))
I worked out an answer to my own question
Here is the formula
=date(year(A12),month(A12), day(A12) + mod(C12+ 7-WEEKDAY(A12),7))
This worked for me:
=TODAY()+MOD(4 + 7-WEEKDAY(TODAY()),7)
Just replace TODAY() and 4 (weekday#) for your context.
This is the formula you are seeking.
=A12+(7-WEEKDAY(A12)+B12)
A12 holds the start date. B12 holds the ID of the targeted weekday, e.g. 1 for "Sunday".
A11 must hold a true date, as opposed to a text string that looks like a date. If the latter is the case an error will be displayed. The result is always a date. You can format that date as "dddd" to display a day's name or "dddd, dd-mm-yyyy" to display both date and day.
And here are the mechanics of the formula:- A12-WEEKDAY(A12) returns always the previous Saturday, a date that is always in the past. A12+(7-WEEKDAY(A12)) inverts that calculation, returning always the next Saturday. This date is always in the future except when A12 is a Saturday. That's when the result will be = A12.
Having found a stable base, you can just add the day you want to the Saturday you have. Add 1 (for Sunday) and you get a Sunday. Add 7 and you get a Saturday. All these dates will be in the future.
That's all as you want it except that if WEEKDAY(A12) = B12 you want the same date as in A12 which is a week earlier than the one the formula prefers. This is where I went wrong while in haste. My apologies! This is the correct modification of the formula's result, to wit, conditionally deduct 7 from the calculation.
=A12+(7-WEEKDAY(A12)+B12)-IF(WEEKDAY(A12)=B12,7,0)
I'm using the following formulas to obtain the start date and end date of the week number, given the week number and the year:
Start of week:=MAX(DATE(A2,1,1),DATE(A2,1,1)-WEEKDAY(DATE(A2,1,1),2)+(B2-1)*7+1)
End of week: =MIN(DATE(A2+1,1,0),DATE(A2,1,1)-WEEKDAY(DATE(A2,1,1),2)+B2*7)
It seems to work well except that week 1 of 2019 begins on 31-12-2018 but my formula for the start date of the week 1 shows it as 01-01-2019. What is the problem with my formula?
Just subtract 6 from the end date formula
=(MIN(DATE(A2+1,1,0),DATE(A2,1,1)-WEEKDAY(DATE(A2,1,1),2)+B2*7))-6
As I noted in my comment, the easiest way is just to subtract 6 from your end date. If your data is in a table, your formula would be =[#EndDate]-6. Otherwise, it would be something like =E2-6.
I have a Date. Ex: 1/1/2017.
I have a week number. Ex: WEEKNUM(1/1/2017) = 1.
How can I list all 7 days, starting from Monday - Ending on Sunday.
Thanks
The way to do it is like this:
=Text(A1,"dddd")
Or if I understood you correctly, something like this may do the job:
=(A1*7)+Date(2017,1,1) to give you the first day in the a1 week.
You may add +1 at the end of the formula.
In general, some interesting formulas here:
http://www.mrexcel.com/archive/Dates/29795.html
Edit:
Try this :
=DATE(Yr,1,1+(Nth-(Dow>=WEEKDAY(DATE(Yr,1,1))))*7)+
Dow-WEEKDAY(DATE(Yr,1,1))
Taken from here:
http://www.cpearson.com/excel/DateTimeWS.htm#NthDoWYear
With week numbers in Row1 (1 in A1) then in A2 copied down to A8 and A2:A8 across to suit:
=DATEVALUE("1/1/17")+7*(A$1-1)+ROW()-1
I have a list of periods (given by period start, period end) in Excel and I have to calculate exactly how many months (as a fraction) are during that period.
E.g. if given a period January 15th to March 7th, then this would be
15-01-2015 until 31-01-2015 = 17 days
01-02-2015 until 28-02-2015 = 28 days
01-03-2015 until 07-03-2015 = 7 days
Months during period = 17/31 + 28/28 + 7/31 = 1,774193548 months
Note that in this calculation, start date and end date are both counted as part of the period.
As the periods can be anything, then I haven't been able to figure out to calculate this with an Excel formula (or if it's even possible).
Any ideas?
Well it's not pretty, but if you have a start date at A1 and an end date at A2, then:
=12*(YEAR(A2)-YEAR(A1))+MONTH(A2)-MONTH(A1) +
(DAY(A2)/(DATE(YEAR(A2),MONTH(A2)+1,1)-DATE(YEAR(A2),MONTH(A2),1))) -
((DAY(A1)-1)/(DATE(YEAR(A1),MONTH(A1)+1,1)-DATE(YEAR(A1),MONTH(A1),1)))
The way this works is:
12*(YEAR(A2)-YEAR(A1)): Difference in year times 12.
+MONTH(A2)-MONTH(A1): (plus) Difference in months.
+(DAY(A2)/(DATE(YEAR(A2),MONTH(A2)+1,1)-DATE(YEAR(A2),MONTH(A2),1))): (plus) Day of end date divided by the total days in end month, calculated by the diff between that month's 1st and the following month's 1st.
-((DAY(A1)-1)/(DATE(YEAR(A1),MONTH(A1)+1,1)-DATE(YEAR(A1),MONTH(A1),1))) (minues) Day of start (minus 1 to not count that day) month divided by the total days in start month.
Of course you duplicate that for any set of cells...
Assuming column A lists the start dates and column B lists the end dates:
=SUMPRODUCT((1+B1:B3-A1:A3)/DAY(DATE(YEAR(A1:A3),MONTH(A1:A3)+1,)))
Note: you will need to increase the depth of the ranges to suit your needs... just change the 3s to a deeper row number.
UPDATE
Based upon your feedback and new requirement, here is a version of the above formula that will calculate the total, one row at a time:
=(1+B1-A1)/DAY(DATE(YEAR(A1),MONTH(A1)+1,))
UPDATE 2
Based on new information that the interval on one row can exceed one month, here is a new version of the formula:
=DATEDIF(A1-DAY(A1)+1,B1,"m")-1+(1+EOMONTH(A1,0)-A1)/DAY(DATE(YEAR(A1),MONTH(A1)+1,))+(B1-EOMONTH(B1,-1))/DAY(DATE(YEAR(B1),MONTH(B1)+1,))
IMPORTANT NOTE: After confirming this formula you will need to apply GENERAL number formatting to the cell. This is because Excel will try to apply DATE number formatting unnecessarily.
Why don't you use:
=12*YEARFRAC(StartDate,EndDate)
I have a column of days of the week in an Excel 2008 spreadsheet. In another column, I want to execute code that involves the Friday in the current row and its following Friday further down in the column. The problem is, it's five years of data that lists the days consecutively for most weeks, but sometimes there's a day missing in the week due to holidays. Hence I can't reference a fixed number of cells away to compare data from Friday to Friday.
So I'm looking for a means of doing the following pseudo-code:
=if(xcell = "Friday" and the_next_cell_named_Friday_down_in_the_list = "Friday", do "code that works with the row xcell is in and the row the next Friday cell is in")
I know there's a way of doing it, but I can't quite see how to execute it.
(If it's not too hard to answer this as well, I also want to be able to do the same thing as above, except check the Friday after the next (every two weeks).)
Use VLOOKUP to find the next "Friday" down in the column of days. E.g.: if column of days is column A, and the row you are currently on is 4, while the last row in column A is 86523, then the correct formula to find the next "Friday" is:
VLOOKUP("Friday", A5:A86523, 1, FALSE)
However this will give you back "Friday" if there is a next "Friday" after row 4, and will give you #N/A error if there isn't - not very useful. You can manipulate table_array (A5:A86523), or index_number (1) to get back something more useful.
For help on the VLOOKUP function click here.
=match("xyz",a1:a3,0)
appears to do it
OP's own answer will not "copy down" so I suggest:
=IF(A2="Friday",MATCH("Friday",A3:A$20,0)+ROW(),"")
Extend range limit to suit.