Excel Formula: Current 12 months - excel

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 :)

Related

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)

How to collect number of days from a month in excel

I have a column which will have some days from a month in dd-mm-yyyy format. What I need to get total number of days from each month mentioned in that column. The column might not contain all days from each month.
Example :
Column A :
2017-01-01
2017-01-02
2017-01-17
2017-01-27
2017-02-08
In above example, from 2017 Jan, I have 4 days and from Feb I have one day. I need this count for a IF statement to run in C column. ie, in C1 there will be an IF function which will check the month in A1 and count the total number of days for that specific month from A column. If that count is below a specific digit, I need to perform a formula otherwise a different one. This will repeat for all C cell
If this column contains all date from each month I can use Day function to get total days, but here how Can I collect it
This will work: =SUMPRODUCT(1*(MONTH($A1:$A5)=D1))
And an example of manipulating basing on the result:
=IF(SUMPRODUCT(1*(MONTH($A1:$A5)=D1))<3;"good";"bad")
Another one when row number represents a month (JAN in C1, FEB in C2...):
=IF(SUMPRODUCT(1*(MONTH($A1:$A5)=ROW()))<3;"good";"bad")
In your case:
=IF(SUMPRODUCT(1*(MONTH($A1:$A5)=ROW()))<10;function1();function2())
Array formula - use Ctrl+Shift+Enter:
=SUM((MONTH($A$1:$A$5)=MONTH(A1))*(YEAR($A$1:$A$5)=YEAR(A1)))

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

Randomly generate 2 dates per week over 2 years

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

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

Resources