Average number of days between start and end dates that are within a specific month

ppalmer1

New Member
Joined
Feb 5, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am trying to write a formula that will calculate the average number of days between start and end dates in a dataset, only including end dates that are within a specific month.

To clarify, if the data is based on the table below (sheet name "Data"), and I only want the average of jobs completed in January, how would I write the formula?

Keep in mind, column C is only for reference in this question and is not in the spreadsheet. I have a separate sheet with this formula to show only the result, without needing to input sub-calculations in each row.

A​
B​
*This column will not be on the spreadsheet. I have a separate sheet with this formula to show only the result, without needing to input sub-calculations in each row.​
Start DateEnd DateAverage
1/4/20231/6/20232
12/28/20221/4/20236
12/29/202212/30/20221
4 (2+6)/2Row 3 should not be included because it ended in December.

The sheet with the formula is using months, formatted as 'mmmm' to reference the criteria.

Here is a table showing what I have tried so far:

A​
B​
Formula Used
January
Call value 1/1/2023, formatted as date (mmmm)
Jobs completed this month​
2​
=COUNTIFS(Data!B:B,">="&$B2,Data!B:B,"<"&EOMONTH($B2,0)+1)
Average time to completion​
Need Formula
These are the formulas I have attempted, but all have errors:

=if((Data!B:B">="&$B2,Data!B:B,"<"&EOMONTH($B2,0)+1),AVERAGE(IF(ISNUMBER(Data!B:B),Data!B:B-Data!A:A)),0)

=average(if(and(Data!B:B">="&$B2,Data!B:B"<"&EOMONTH($B2,0)+1),Data!B:B-Data!A:A)

=averageif(Data!A:B,(Data!CB:B,">="&$B2,Data!B:B,"<"&EOMONTH($B2,0)+1),Data!A:A-Data!B:B)

I am still learning and I know these formula attempts are terrible. Please forgive my ignorance. Any help would be greatly appreciated.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
why is row 2 = 6 ?
a sumproduct may help here
But just need to make sure i understand why you get 6 days ........
something like
=SUMPRODUCT((B2:B6>=E1)*(B2:B6<=EOMONTH(E1,0))*((B2:B6)-(A2:A6)))/COUNTIFS(B2:B6,">="&E1,B2:B6,"<="&EOMONTH(E1,0))
Where E1 has the date ie 1/1/23

the other alternative is to have a helper column in the data set and b2-a2 will give the number of days
and then you can use SUMIFS() / countifs()

or as you are version 365 , you have averageifs()
 
Upvote 1
Hi & welcome to MrExcel.
Why is the 2nd row 6 rather than 7?
Maybe
Excel Formula:
=AVERAGE(IF((Data!B2:B10<=EOMONTH(B2,0))*(Data!B2:B10>=B2),DAYS(Data!B2:B10,Data!A2:A10),""))
 
Upvote 1
Solution
why is row 2 = 6 ?
a sumproduct may help here
But just need to make sure i understand why you get 6 days ........
something like
=SUMPRODUCT((B2:B6>=E1)*(B2:B6<=EOMONTH(E1,0))*((B2:B6)-(A2:A6)))/COUNTIFS(B2:B6,">="&E1,B2:B6,"<="&EOMONTH(E1,0))
Where E1 has the date ie 1/1/23

the other alternative is to have a helper column in the data set and b2-a2 will give the number of days
and then you can use SUMIFS() / countifs()

or as you are version 365 , you have averageifs()
Thank you. This worked great.
btw, I got 6 because I was just counting the days manually when I typed up this forum question. my mistake.
 
Upvote 0
Hi & welcome to MrExcel.
Why is the 2nd row 6 rather than 7?
Maybe
Excel Formula:
=AVERAGE(IF((Data!B2:B10<=EOMONTH(B2,0))*(Data!B2:B10>=B2),DAYS(Data!B2:B10,Data!A2:A10),""))
Thank you. This worked great.
btw, I got 6 because I was just counting the days manually when I typed up this forum question. my mistake.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top