Randomly generate 2 dates per week over 2 years - excel

How do I write an excel formula, which randomly picks 2 dates in each week over a 2 year period, where:
The 2 dates per week are not the same as each other
So this should not happen:
05/02/2015
05/02/2015
The first date in any given week is always before the second date of that same week:
So this should not happen:
06/02/2015
05/02/2015
Where Sunday is the beginning of the week and Saturday is the end of the week:
Here is an example of what I am after:
week day date
1 1 01/01/2015
1 2 03/01/2015
2 1 05/01/2015
2 2 08/01/2015
And so on, all the way to the end of 2016.
This is what I have so far, but this only randomly gives me a day of a week, and doesn't fulfill any of the criteria I've described above:
=CHOOSE(WEEKDAY(ROUND((RAND()*(7-1)+1),0)),"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")

There are 21 different combinations of 2 days in a week - to ensure an even distribution you can use a helper column, so assuming your weeks start at A2 and days at B2 (always showing 1 then 2 in days column for each week) then use this formula in D2
=IF(B2=1,RANDBETWEEN(1,21),"")
and this formula in C2
=IF(B2=1,E$1+MATCH(D2,{1,7,12,16,19,21})-8+A2*7,C1+D1-LOOKUP(D1,{1,7,12,16,19,21})+1)
where E1 contains the start date (a Sunday) of week 1
fill both formulas down the column
You can hide column D if required
See example here

Related

How to get week number of the month by week number of the year

I only have week number for the year. How can I get the week number of the month?
For ex:
Week
42
Week of the month
2
How can I get the “2” in excel?
I have created a formula for you.
=INT( DAY( (A1-1)*7+ (DATE(B1,1,1)+ (8-WEEKDAY(DATE(B1,1,1),2))) ) / 7)
The formula is inserted in C1, year is present in B1 and week number is present in A1
Week numbers are according to ISO stranded.

How to calculate the number of weeks between 2 date range in excel

I have a question here, I have 3 columns in excel, A1 is being the calendar date; column B1 has the fiscal_quarter_start_date ; and fiscal_quarter_end_date in column C1.
I am trying to find the number of week falling in between the A2 and A3. The issue here is I should consider the first sunday as the first week of the quarter. My fiscal year starts on Feb of every month.
The reason I am doing this calculation is to populate the count of weeks numbers of a quarter, where my first week starts from the first sunday of the quarter.
=ROUNDUP(MOD(IF(A13>=IF(DATE(YEAR($A13),2,1)=1,DATE(YEAR($A13),2,1),DATE(YEAR(A13),2,7-WEEKDAY(DATE(YEAR(A13),2,1),1)+2)),ROUNDUP((A13-IF(WEEKDAY(DATE(YEAR(A13),2,1),1)=1,DATE(YEAR($A13),2,1),DATE(YEAR($A13),2,7-WEEKDAY(DATE(YEAR($A13),2,1),1)+2))+1)/7,0),ROUNDUP((A13-IF(DATE(YEAR($A13)-1,2,1)=1,DATE(YEAR($A13)-1,2,1),DATE(YEAR($A13)-1,2,7-WEEKDAY(DATE(YEAR($A13)-1,2,1),1)+2))+1)/7,0)),13.01),0)
above is the formula i've got all the way. However rounding up with 13 is not a viable solution as its not necessary that it should have always have 13 weeks all the time.
For example: 5/1/16 should be week 1 As it is a begging of a q2 and 5/1/16 is the starting on Sunday. In this case using above formula result for the week is 13
Please help me..
You can use WEEKNUM to get the week number.
However you mentioned that your week wont end at the Saturday, but at the Sunday, so you have to do =WEEKNUM(<insert here where the date is>,2)
=WEEKNUM (serial_num, [return_type])
serial_num - A valid Excel date in serial number format.
return_type - [optional] The day the week begins. Default is 1.
Return_type can either be 1 or 2:
1 - Week begins on Sunday
2 - Week begins on Monday
or... read it here for counting weeks between 2 dates.
Enter this formula =(A2-A1)/7 into a blank cell, (A2 indicates the end date and A1 is the start date)
If you just want to get the whole weeks, please apply this INT function: =INT((A2-A1)/7)
Try it here, on sheet "week"
Hope it'll help.
Assuming that the Quarter start and end dates are in A3:A6 respectively then:
=IF(AND(C1>=$A3,C1<$A4),WEEKNUM(C1)-WEEKNUM($A3)+1,IF(AND(C1>=$A4,C1<$A5),WEEKNUM(C1)-WEEKNUM($A4)+1,IF(AND(C1>=$A5,C1<$A6),WEEKNUM(C1)-WEEKNUM($A5)+1,WEEKNUM(C1)-WEEKNUM($A6)+(IF(AND(C1>=DATE(YEAR(C1),1,1),C1<DATE(YEAR(C1),MONTH($A6),DAY($A6))),53,1)))))
This is checking whether the date in the cell above (C1) is between the quarter start and end dates, and checking the difference in weeks from the start date. To cover the anomoly for Q4 extending into the next year, the IF statement at the end adds 53 instead of 1 for the affected dates.
Edit #1
=WEEKNUM(A1)-WEEKNUM(B1)+IF(AND(A1>=DATE(YEAR(A1),1,1),A1<DATE(YEAR(A1),MONTH(B1),DAY(B1))),53,1)
This works for the A1:C1 format you mentioned in your comment. Obviously this relies on B1 and C1 being updated manually.
Edit #2
=WEEKNUM(C1)-WEEKNUM(B1)
If you are counting 05/01/2016 as week 1 then add 1 to the result. Take off the highest week number (default is counting from sunday or you can change to (C1,1) if you want to define it exactly) from the lowest week number. Reult is 13 which would match the manual calculation.
You will want to look at the previous edit for an example of the if formula you will need when the quarter ends in another year. to reverse the negative figure it will need to add 52 when the date is in the early part of the next year and 0 when it is not.
You can use the "hidden" function DATEDIF:
For example in A1 we write start date (01/05/2016), in B1 - end date (31/07/2016) and in C1 = DATEDIF(A1,B1,"d")/7 the result will be 13

Excel Formula: Current 12 months

I'm looking for a formula in excel that will give me a current 12 month table. For example this month is April. I want a formula that gives me 12 months back from April in the exact format as show in the table below. For next month it will be May, and 12 months back from may without having to adjust any dates.
Month
5/1/2015
6/1/2015
8/1/2015
9/1/2015
10/1/2015
11/1/2015
12/1/2015
1/1/2016
2/1/2016
3/1/2016
4/1/2016
Thank you
Try this and copy down 11 rows
=EDATE((TODAY()-DAY(TODAY())+1),ROW(A1)-12)
If you number the months in column b starting from b2 =0 to b13=11
And row 1 has headers
A2 formula =EOMONTH(today(),b2-1)+1
A3 formula = EOMONTH(today(),b3-1)+1
Etc.
EOMONTH will give you the last day of any month. So if we start with today() it will give you the last day of the current month, but if we count back 1 month (b2-1). It will give you the last day of last month. So we add 1 day to it and you get the first day of each month.
Hope this helps :)

Excel: Sum partial weeks for EOM report

I'm looking for a formula that will let me get a weekly total of a daily totals column during partial weeks at the end month for Excel 2010. Using the US week of Monday-Friday.
I have a Day(A), Date(B), Daily Total(J) and Weekly Total(N) column for one month. I'd like to show the totals for the week (M-F) either on Fridays, or the last day of the month. For full weeks, if the Day="Fri", I can sum column J by using a 5 cell range like $J11-$J15 which would sum the daily totals from Monday thru Friday of a full week in the middle of the month.
That doesn't work for a partial week at the beginning, so I have modified versions for the first 5 days, if a Friday is detected and that seems to work. I'm open to other ideas if there's a better way to handle the first week.
--------------------------------------------------------------------
A B J (N) Week
1 Day Date Total Total Formula for Column N Week Total
2 Thu 1/1/2015 1 =IF($A2="Fri",$J2,"")
3 Fri 1/2/2015 2 3 =IF($A3="Fri",SUM($J$2:$J3),"")
4 =IF($A4="Fri",SUM($J$2:$J4),"")
5 =IF($A5="Fri",SUM($J$2:$J5),"")
6 =IF($A6="Fri",SUM($J$2:$J6),"")
--------------------------------------------------------------------
A6/N6 would be the last possible Friday for the first 5 days of the first week, so the rest of the formulas, until towards the end of the month are similar to:
N7 would be =IF($A7="Fri",SUM($J3:$J7),"")
N8 would be =IF($A8="Fri",SUM($J4:$J8),"")
It handles summing a 5 day full week, in the middle of the month, and only shows the weekly total in column N for Fridays.
I don't know how to handle the last week since it could be a partial week of between 1-4 weekdays, not ending on a Friday. I still want show a total for that last partial week, on the last weekday of the month.
I thought about checking to see if the days in the last week were either Friday or the end of the month, and came up with a check for either "Fri" or the end of the month. For example in January day 31 would be:
(N32) =IF(OR($A32="Fri",EOMONTH($B$2,0)=$B32),SUM($J28:$J32),"")
That works if and only if, the 31st is a Fri, but doesn't work if Jan 31st is a Mon-Thurs since the range to sum is fixed at 5 days ($J28:$J32) and I don't know how to make it variable, based on how many days are in that last week of the month.
I would appreciate your ideas on how to do a monthly report where it can show weekly totals for full or partial weeks. The "plan" is to have 4 empty master workbooks to use for months with 28, 29, 30 and 31 days since I don't know how to make it all purpose and not screw up borders.
Thanks!
Does your data include Saturdays or Sundays? I'm assuming not. If not then you need to check whether the date is the last workday of the month....or a Friday.....and you could just sum everything in column J up to that point and subtract the column N totals form above, i.e. in N2 copied down
=IF(B2="","",IF(OR(A2="Fri",MONTH(WORKDAY(B2,1))<>MONTH(B2)),SUM(J$2:J2)-SUM(N$1:N1),""))
I assume N1 will contain a text header

In Excel, how to calculate # of days between a date range, counting only specific days of week

I'm trying to get # days between 2 dates, but had to count only days of the week specified per pair of dates in questions.
For example:
Date of operation = 9/1/2013 and 5/16/2014
Days of the Week in operation = Monday, Wednesday, Friday
I want to calculate total number of days in actual operation, given the days in operation per week.
If you have Excel 2010 or later you can use NETWORKDAYS.INTL function which allows you to customise which days are counted, e.g. the following formula will count Mondays, Wednesdays and Fridays between a start date in A2 and an end date in B2 (inclusive) while excluding holiday dates listed in H2:H10
=NETWORKDAYS.INTL(A2,B2,"0101011",H$2:H$10)
The string "0101011" defines the days to include - 0 is included, 1 is excluded - it starts with Monday
In earlier excel versions you can use this formula for the same result
=SUMPRODUCT((WEEKDAY(ROW(INDIRECT(A2&":"&B2)))={2,4,6})*(COUNTIF(H$2:H$10,ROW(INDIRECT(A2&":"&B2)))=0))
where {2,4,6} defines the weekdays to include (1=Sun through to 7=Sat)
The number of days between to dates is just date1 - date2.
One method is to divide the number of days in operation by the number of days in the week. In this case that would be 3/7. In this example, the number of days in operation would be 110.14 days. Below is your example. cell B4 has 1-sep-13, b6 has 16-may-14, both formatted as dates.
B
4 41518
6 41775
8 =B6-B4 Days
9 =B8/7 Weeks
10 =B8*3/7
01-Sep-13
16-May-14
257 Days
36.71 Weeks
110.14
To get more accurate, you would need to know which day of the week, weekday(), the first day in your range was and which day of the week your last day was.

Resources