Date formula previous month for a new year
I'm still getting my head around date formulas, I have one to tell me the start date of the previous month:
=IFERROR(DATE(YEAR([Date Column]@row), MONTH([Date Column]@row) - 1, 1), DATE(YEAR([Date Column]@row) + 1, 1, 1))
This worked fine until we changed to a new year, what have I done wrong with this formula?
Best Answer
-
Yes. The first MONTH function should be minus one. Not minus twelve.
Answers
-
The second DATE function needs a couple updates. Change the year to be minus 1 instead of plus 1 and the month to 12 instead of 1.
-
Thank you - I have adjusted to the following =IFERROR(DATE(YEAR([Date Column]@row), MONTH([Date Column]@row) - 12, 1), DATE(YEAR([Date Column]@row) - 1, 1, 1))
If the [Date Column] says a date in January 2023 it's showing 1st January 2022 instead of 1st December 2022 - have I done it correct to your suggestion?
-
Right. The second change I suggest should take care of that. Change the month number in the second DATE function from 1 to 12.
-
Thank you appreciate your help! Does this mean the formula will need to be changed back again after the end of this month? There isn't a formula that would calculate the previous month even in January of a new year?
-
You shouldn't need to change anything. That is why there is two separate DATE functions.
The first one will run to grab the typical month minus 1. If that throws an error (in January) then the second DATE function will run.
-
Ok thank you that's interesting - do I still do have the formula wrong then? This is what I have now:
=IFERROR(DATE(YEAR([Date Column]@row), MONTH([Date Column]@row) - 12, 1), DATE(YEAR([Date Column]@row) - 1, 12, 1))
If I put in the [Date Column] today's date (12/1/2023) then it correctly returns 1/12/2022
But if I put in [Date Column] 11/2/2023 (or a date in Feb 2023) it still returns 1/12/2022
-
Yes. The first MONTH function should be minus one. Not minus twelve.
-
Ok thank you! So sorry for the misunderstanding. This works perfectly now! Very much appreciate your help!
-
No worries. Happy to help. 👍️
Help Article Resources
Categories
- All Categories
- 14 Welcome to the Community
- Smartsheet Customer Resources
- 64K Get Help
- 410 Global Discussions
- 220 Industry Talk
- 459 Announcements
- 4.8K Ideas & Feature Requests
- 143 Brandfolder
- 137 Just for fun
- 57 Community Job Board
- 459 Show & Tell
- 31 Member Spotlight
- 1 SmartStories
- 298 Events
- 37 Webinars
- 7.3K Forum Archives
Check out the Formula Handbook template!