Define conscutive months

Copper Contributor

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

A17/12/2023
A24/18/2023
A33/22/2023
A42/22/2023
A51/25/2023
A69/7/2022
A78/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!

1 Reply

@ecantu 

=((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.

averageifs.png