Excel calculate the number of calendar days between two dates for individual months - excel

I need to automatically calculate the number of calendar days between two dates for individual months
EG:
Start End Jan2014 Feb2014 Mar2014 Apr2014 May2014
18/11/2013 9/03/2014 31 28 9 0 0
7/04/2014 18/05/2014 0 0 0 23 18
....

you can use this formula in C3 copied across and down if required
=MAX(0,MIN(EOMONTH(C$2,0),$B3)-MAX(C$2,$A3+1)+1)
Assumes that dates in C2 and across are all 1st of the relevant month

Related

How to count number of times someone's tenure falls into each month range in Excel

I am trying to count the number of months someone's tenure falls into each range but am struggling to come up with a formula that works. For example:
Year-End Tenure Year-Start Tenure Month 1-6 Month 7-12 Month 13-24
23 12 0 1 12
56 45 0 0 0
11 0 6 5 0
The first employee starts the year having worked for this company for 12 months and ends the year having 23 months tenure. Therefore, they spent 0 months in the Month 1-6 bracket, 1 month in the Month 7-12 bracket, and 12 months in the Month 13-24 bracket.
The following two examples follow the same logic. I need a formula to calculate the numbers in Month 1-6, Month 7-12, and Month 13-24 columns.

Excel Average Calculation of a Moving Criteria Range

I need to create a logic excel formula that calculates the average of 3 months prior to a specified start date. There are multiple start dates. For instance:
For ID 1, The Start Date is May-2021. I would need for the logic to calculate the average between Feb-2021 to Apr-2021 to get 91.67. For ID 2, the Start Date is Jun-2021, so I would need to calculate the average of Mar-2021 to May 2021 to get 108.33. I also would need to calculate the average of 6 months prior in a separate column.
ID
Start Date
Calculation Result
Jan-2021
Feb-2021
Mar-2021
Apr-2021
May-2021
Jun-2021
1
May-2021
91.67
50
100
75
100
25
0
2
Jun-2021
108.33
0
25
100
175
50
125
3
Apr-2021
83.33
100
150
0
75
0
200
Any help is greatly appreciated! (Not opposed to VBA suggestions either)
use INDEX to create the range.
=AVERAGE(INDEX(D2:I2,MATCH(B2,$D$1:$I$1,0)-3):INDEX(D2:I2,MATCH(B2,$D$1:$I$1,0)-1))
Or if they are true dates we can use AverageIfs:
=AVERAGEIFS(D2:I2,$D$1:$I$1,">"&EOMONTH(B2,-4),$D$1:$I$1,"<="&EOMONTH(B2,-1))

Calculate in Excel Sum of Days given 2 date ranges (Start date , End date), aggregate monthly

Please find the excel data.
Input format:
ID Begin Date End Date Comment
1 07/25/17 08/16/17 July 6 days, August 16 days
2 05/01/17 05/11/17 11 Days in May
3 07/10/17 07/16/17 6 days in July
Output format:
Jan-17 Feb-17 Mar-17 Apr-17 May-17 Jun-17 Jul-17 Aug-17..... Dec
11 12 16
How to get this aggregate at month level, given a range
Input Format:
Output format:
Are you including start date and end date because your results aren't consistent. If ID2 is 11 days then shouldn't ID3 be 7?
Assuming that you want to include both start date and end date then you can do that like this:
Put the first of each month in A8 copied across (formatted as mmm-yy) then use this array formula in A9
=SUM(TEXT(IF($B2:$B4="",0,IF($C2:$C4>EOMONTH(A8,0),EOMONTH(A8,0),$C2:$C4)-IF($B2:$B4<A8,A8,$B2:$B4)+1),"0;\0")+0)
confirm with CTRL+SHIFT+ENTER and copy across
This only counts rows that have both start and end date
See screenshot:

Excel formula to Count zeros only from Left to Right

I am currently using the following formula (i.e. =IF(A9<>"0";COUNTIF(A9:L9;"0");" ")) in a range "Jan to Dec" to get the number of zeros from left to right only and it is giving me 3 for 1st row, second & third rows as well. But what I want is, it should count zeros only from left to right (only in first and third cases). Only in second case it should not count zeros, because they are coming after some value, but it should count in 1st case and 3rd cases.
Can someone please help me with the formula?
Jan Feb Mar Apr May Jun Jul
0 0 0 5 10 15 20
10 15 20 25 0 0 0
50 0 0 0 30 35 40
Per comment conversation with OP vbalearner, assuming your data setup and desired results look something like this:
Then the formula in the cell and copied down is:
=IF(A9=0,IFERROR(MATCH(TRUE,INDEX(A9:L9>0,),0)-1,12),IF(B9=0,IFERROR(MATCH(TRUE,INDEX(B9:L9>0,),0)-1,12),0))
Shortened version:
=IF(OR(A9=0,B9=0),IFERROR(MATCH(TRUE,INDEX(IF(A9=0,A9:L9,B9:L9)>0,),0)-1,12),0)
With a helper row inserted at the top (may be hidden) with month numbers (1 for Jan etc) and assuming Jan is then in A2 please try:
=MIN(IF(A3:G3<>0;A$1:G$1))-1
entered with Ctrl+Shift+Enter and copied down to suit.

Rolling Time LookBack Calculation

I'm sorry if this has been answered. I've been searching around for awhile now.
I have a times series dataset that I need to perform calculations on based on the previous x time (last hour,day, etc).
My issues is that I don't know how to run these calculations since the time deltas are not standardized.
Example:
Column A - Time (in seconds lets say)
Column B - Value
Time Value Result(5)
01 3 0
02 5 3
04 4 8
07 8 9
09 6 12
13 4 6
14 4 10
15 1 8
22 9 0
33 7 0
How could I return the Result(5) column by summing the last 5 seconds from that one instance (row) (not including it)?
Thank you.
EDIT:
To clear up what I'm trying to do:
1) Find the previous 5 secs of data using column A and return that range of rows
2) Using that range of rows for the 5 previous secs, sum column B
3) Output in Column C (formula)
The following formula should do what you need (paste into C2 and drag down):
=SUMIFS($B$2:$B$11,$A$2:$A$11,">="&A2-5,$A$2:$A$11,"<"&A2)
Where YourTime is the time in the row you wish to look back and sum over.
I've tested and it works for the data you provided - expand the ranges as appropriate.

Resources