Community Browser
cancel
Showing results for
Did you mean:

NiCd Battery

## Rolling Months - Previous 12

Is there a good way to calculate previous 12 months, where the lookback is on the calendar month as a whole? E.g. if today is January 15th, 2021 and I want the previous 12 months excluding this month, I would get January 1, 2020 - December 31, 2020.

I have tried the following formulas which do not isolate calendar months;

IF(AND(datediff(endofmonth(@DateField@), endofmonth(today()), "months") >0, datediff(endofmonth(@DateField@), endofmonth(today()), "months") <=12

IF(AND(datediff(@DateField@, today(), "months") >0, datediff(@DateField@, today(), "months") <=12))

Labels (1)
• ### Data

2 Replies
NiCd Battery

I switched to <13 / >0, but that didn't work either.  It was giving me the same result where I had values from 2019 coming through.

Solution was to calculate

2)  Then if the date fell between prior year and month-end prior month: IF(AND(@receivedDate@ >= @PriorYearDate@, @receivedDate@ <= DATEADD(ENDOFMONTH(today()),-1,"months")),"12MM"

DataRobot Alumni

Hi Aaron!

You were very close. Here's how I would do it.

``````AND(
datediff(@Date@,  endofmonth(@Today@), "months") <13,
datediff(@Date@,  endofmonth(@Today@), "months") >0
)``````

Regards,

Shyam