Return 1 if YEAR and MONTH is equal TODAY
Hi,
I have a formula:
=IFERROR(IF(MONTH([Sale Date]2) = MONTH(TODAY()), 1, IF(MONTH([Sale Date]2) = MONTH(TODAY()) - 1, 2)), " ")
and it worked until we have two years in one sheet. I would like to know how to add YEAR to this formula so that we can compare not only MONTH but also YEAR.
Thanks.
Comments
-
Try something along these lines...
=IFERROR(IF(AND(MONTH([Sale Date]2) = MONTH(TODAY()), YEAR([Sale Date]2) = YEAR(TODAY())), 1, IF(AND(MONTH([Sale Date]2) = MONTH(TODAY()) - 1, YEAR([Sale Date]2) = YEAR(TODAY())), 2)), " ")
-
The OG
=IFERROR(IF(MONTH([Sale Date]2) = MONTH(TODAY()), 1, IF(MONTH([Sale Date]2) = MONTH(TODAY()) - 1, 2)), " ")
The New
=IFERROR(IF(date(year(today()),month(today()),1)=date(Year([Sale Date]2),month([Sale Date]2),1),1,if(Date(Year(today()),month(today()),1)-1 = Date(year(today()),month(today()),1)-1,2
Paul, your will break in january. 1 - 1 = 0 not 12. Learned that the hard way earlier this year.
-
tried to edit but got cloudflared. I forgot to add the end of the iferror statement
=IFERROR(IF(date(year(today()),month(today()),1)=date(Year([Sale Date]2),month([Sale Date]2),1),1,if(Date(Year(today()),month(today()),1)-1 = Date(year(today()),month(today()),1)-1,2)),"")
-
Correct. I wasn't paying attention to the details. I just saw the request to include in the YEAR criteria and went with it.
Good catch.
Help Article Resources
Categories
- All Categories
- 14 Welcome to the Community
- Smartsheet Customer Resources
- 64.2K Get Help
- 419 Global Discussions
- 221 Industry Talk
- 461 Announcements
- 4.8K Ideas & Feature Requests
- 143 Brandfolder
- 142 Just for fun
- 58 Community Job Board
- 462 Show & Tell
- 32 Member Spotlight
- 1 SmartStories
- 299 Events
- 38 Webinars
- 7.3K Forum Archives
Check out the Formula Handbook template!