Excel count if date range is active in a certain month - excel

I have 2 date, a start date and end date. I want to be able to count if these were active through a certain month.
Row 1: start date 20/11/2020, end date 03/02/2021.
Row 2: start date 03/01/2021, end date 15/03/2021
Row 2: start date 12/01/2021, end date 31/03/2021,
The columns I have are the months and based on the above data this is the expected result.
Nov 1
Dec 1
Jan 3
Feb 3
Mar 2
Is there a formula that I can use to count this through a range of 100's of rows?

A simpler method than what you posted in your comment.
Put your start/end dates in a Table and name it StartEndTbl
Create a column of months whereby
Each entry is the first day of the month
The column is formatted mmm-yyy
In the first cell (F2 in this case), enter the formula:
F2: =SUM((StartEndTbl[Start]<=EOMONTH(E2,0))*(StartEndTbl[End]>=E2))
and fill down as far as needed

Related

Excel Date Formula + 3 Months

I am looking to have a formula that takes the date that is manually input in a cell (E2) and automatically populates a date in the column next to it (F2) that is + 3 months from the date manually input in (E2).
eg. If (E2) has 03/11/2021 input manually then the formula in (F2) would populate 03/02/2021. image of part of the sheet
Is this what you are looking for?
=DATE(YEAR(A1),MONTH(A1)+X,DAY(A1))
where X = 3
One can use EDATE():
=EDATE(A1,3)
The second criteria is the number of Months to add.
EDATE will go to the number of months then try to equate the day. If the day exceeds the number of days in the target month it returns the last day of the target month.
For example =EDATE(DATE(2021,11,30),3) will return the 28th of February 2021.

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

Fill a cell range based on start and end date (which will change)

My start and end dates will continually change. I need the appropriate cells to highlight the appropriate range between the start and end dates. Each column will have a date heading. The dates will be a month and year and run for a year. For example, Jan 15, Feb 15, Mar 15......Jan 16. How should I write this formula?
Thanks for your help in advance.
If my image does not post, the excel sheet will look like:
|Supervisors|Job Number|Start date|End Date|Jan-15|Feb-15|Mar-15...
| John Doe |12345-67 | Jan 15 |June 15 |xxxxx |xxxxx |xxxxx
Just to clarify the question, you want to put in one heading for each month between the start and end date?
You can use the MONTH() function to extract the month from a date. So using VBA, you could do something like
for index = 0 to (month(enddate) - month(startdate))
'Insert a header
next index
You can do the same with year if they are not all in the same year.

Excel: Extract full months between date ranges

Users are entering date ranges into an Excel spreadsheet. These date ranges span multiple months. What I'd like is for a field to display how many full months are represented in the date range.
For example:
User enters 8/25/2014 and 12/19/2014
Calculated field = 3
The full months represent September, October, and November. August and December are only partial months.
Assuming start date in A2 and end date in B2 use this formula for the number of full months
=DATEDIF(EOMONTH(A2-1,0)+1,B2+1,"m")
That will give you 3 for your example - if you change the start date to 8/1/2014 (or the end date to 12/31/2014) you will get 4 (or if you do both you'll get 5)

Calculate the number of days of a date range occur between two dates

I have a datasheet that contains a list of start and end dates for a task. I need to calculate how many days between the start date and end date are part of our Christmas break (11th December to 7th January)
So for example,when start date is 10/12/2012 and end date is 12/01/2013, 28 of the days are between those dates. when the start date is 15/12/2012 and the end date is 12/03/2013, then 22 days of days are between those dates. If the start date is 10/12/2012 and the end date is 12/01/2014, 56 of the days are between those dates (because there's two years of the range).
I need to do this with a formula because of the requirements that I've been set.
Initially I decided to use the number of times Christmas Day (25th December) occurs and just calculate 4 weeks per occurrence.
The formula I used was
=FLOOR((E12-A25)/365,1)+IF(OR(MONTH(E12)=12,
MONTH(A25)=12),
IF(AND(DAY(A25)<=25,DAY(E12)>=25),1,0),
IF(OR(MONTH(A25)>=12,
IF(MONTH(E12)<MONTH(A25),
MONTH(E12)+12,
MONTH(E12))>=12),1,0))*28
But obviously this doesn't help if the range start and end date falls between those two dates.
Any suggestions? I'm at a dead end
Your date math on the second example is wrong -- there are 24 days in that range, not 22.
I can get you there for one holiday period:
LET:
A1 contain the holiday start (11-Dec-2012)
A2 contain the holiday end (7-Jan-2013)
B1 contain the start date
B2 contain the end date
FORMULA:
=MAX(MIN(A2+1,B2+1),A1) - MIN(MAX(A1,B1),A2+1)
The formula basically finds the overlapping date range, if there is one, and subtracts to get the number of whole days. The "+1" is because your "end dates" are actually inclusive, so for date math you need to have the holiday ending on 8 Jan, not 7 Jan, to capture that last day.
But this only works for a single year's holiday. You could store holiday ranges in other cells and use the same formula and add them all up, but you'll be limited to however many years you set up.
This formula will count dates between 11th December and 7th January inclusive within any date range, even across multiple years
=SUMPRODUCT((TEXT(ROW(INDIRECT(B1&":"&B2)),"mmdd")+0>=1211)+(TEXT(ROW(INDIRECT(B1&":"&B2)),"mmdd")+0<=107))
where your start date is in B1 and end date in B2
This converts every date in the range to a number , e.g. 1st Dec becomes 1201, 4th March becomes 304, then it counts those dates that are either greater or equal to 1207 (7th December) or smaller than or equal to 107 (7th January), so that will give 56 for your last example
You can shorten the formula if you subtract 7 from every date (based on 7th January as the end date) then you only need to check that resultant numbers are >= 1204, i.e.
=SUMPRODUCT((TEXT(ROW(INDIRECT(B1-7&":"&B2-7)),"mmdd")+0>=1204)+0)
.....and a third option which should also give the same result, closer to richardtallent's approach - gets the number of years and multiplies by 28 and then adjusts the figures based on the start/end date
=(YEAR(B1-7)-YEAR(B2-7)+1)*28-MAX(0,B2-DATE(YEAR(B2-7),12,11))-MIN(28,DATE(YEAR(B1-7)+1,1,7)-B1)

Resources