Aug 12 2023 05:59 AM
Hi everyone!
I am trying to get the average length between two dates only for consecutive months.
To get the average length between dates I am using =AVERAGE(DATEDIF(A2,A1,"d"),(DATEIF(A3,A2,"d",)...)
But as you can see, not all months are consecutive and I only want the days between consecutive months (between A7&A6, A5&A4, A4&A3, etc...)
Dates
A1 | 7/12/2023 |
A2 | 4/18/2023 |
A3 | 3/22/2023 |
A4 | 2/22/2023 |
A5 | 1/25/2023 |
A6 | 9/7/2022 |
A7 | 8/10/2022 |
I was thinking of using AVERAGEIF but I don't know how to define consecutive months in the criteria.
Thanks for the help!
Aug 12 2023 06:38 AM
=((YEAR(A2)=YEAR(A1))*(MONTH(A2)=MONTH(A1)+1))+((YEAR(A2)=YEAR(A1))*(MONTH(A2)=MONTH(A1)-1))
=IF(A1-A2<0,A2-A1,A1-A2)
=AVERAGEIFS(C2:C7,B2:B7,1)
AVERAGEIFS with these helper formulas in cells B2 and C2 returns the expected result in my sheet.