Help with Nested If Function
Hey guys I am working with lease end dates and I am trying to create a nested if statement that says, If the extended lease end date is over 30 days away then "green". If the extended lease end date is less than 30 days away or today then turn "yellow". If the extended lease end date is past todays date then turn "Red". I have the first two correct I believe but I can't seem to get the last part to work. What am I doing wrong here? Any help would be appreciated.
=IF([Extended End Date]@row > today(30), "Green", IF([Extended End Date]@row <= today(30), "Yellow", IF([Extended End Date]@row < today(), "Red")))
I am also trying to include a contingent where the [End Date] shows "N/A" as well and can't get that to work either. I am not sure I have this correct.
=IF([Extended End Date]@row > TODAY(30), "Active", IF([Extended End Date]@row <= TODAY(30), "Almost Expired", IF(AND(Today() - [End Date]@row < "1d", [Extended End Date]@row = "N/A", "Expired")))
Best Answer
-
IF statements will stop as soon as they find a statement that is "True". This means that in your first formula, you'll never have "Red" since your previous statement is already looking for something that's "Less than TODAY", so all of your ones in the past will be Yellow.
Instead, try putting that Red statement first. Then you can have the Yellow statement second, and then we don't even need to write a Green statement because anything left over will be greater than 30 days from now!
=IF([Extended End Date]@row < TODAY(), "Red", IF([Extended End Date]@row <= TODAY(30), "Yellow", "Green"))
For your next formula, there's a couple of things to note. When you subtract a date from a date you'll receive a number as the output. This means that TODAY() - [End Date]@row will never equal "1d", but instead will simply equal 1.
Today() - [End Date]@row < 1
You will also need to close off the AND() statement before you can tell it to say "Expired".
IF(AND(TODAY() - [End Date]@row < 1, [Extended End Date]@row = "N/A"), "Expired")
Try this, putting your "N/A" statement first:
=IF(AND(TODAY() - [End Date]@row < 1, [Extended End Date]@row = "N/A"), "Expired"), IF([Extended End Date]@row > TODAY(30), "Active", IF([Extended End Date]@row <= TODAY(30), "Almost Expired")))
Let me know if this works for you!
Cheers,
Genevieve
Join us at Smartsheet ENGAGE 2024 🎉
October 8 - 10, Seattle, WA | Register now
Answers
-
IF statements will stop as soon as they find a statement that is "True". This means that in your first formula, you'll never have "Red" since your previous statement is already looking for something that's "Less than TODAY", so all of your ones in the past will be Yellow.
Instead, try putting that Red statement first. Then you can have the Yellow statement second, and then we don't even need to write a Green statement because anything left over will be greater than 30 days from now!
=IF([Extended End Date]@row < TODAY(), "Red", IF([Extended End Date]@row <= TODAY(30), "Yellow", "Green"))
For your next formula, there's a couple of things to note. When you subtract a date from a date you'll receive a number as the output. This means that TODAY() - [End Date]@row will never equal "1d", but instead will simply equal 1.
Today() - [End Date]@row < 1
You will also need to close off the AND() statement before you can tell it to say "Expired".
IF(AND(TODAY() - [End Date]@row < 1, [Extended End Date]@row = "N/A"), "Expired")
Try this, putting your "N/A" statement first:
=IF(AND(TODAY() - [End Date]@row < 1, [Extended End Date]@row = "N/A"), "Expired"), IF([Extended End Date]@row > TODAY(30), "Active", IF([Extended End Date]@row <= TODAY(30), "Almost Expired")))
Let me know if this works for you!
Cheers,
Genevieve
Join us at Smartsheet ENGAGE 2024 🎉
October 8 - 10, Seattle, WA | Register now -
Hey Genevieve,
That worked perfectly! You are a life saver! I messed with that formula for way to long. I guess I need to use them more often. Thank you so much!
-
No problem at all! I'm glad I could help. 🙂
Join us at Smartsheet ENGAGE 2024 🎉
October 8 - 10, Seattle, WA | Register now
Help Article Resources
Categories
- All Categories
- 14 Welcome to the Community
- Smartsheet Customer Resources
- 62.8K Get Help
- 376 Global Discussions
- 207 Industry Talk
- 440 Announcements
- 4.5K Ideas & Feature Requests
- 139 Brandfolder
- 129 Just for fun
- 130 Community Job Board
- 449 Show & Tell
- 30 Member Spotlight
- 1 SmartStories
- 284 Events
- 33 Webinars
- 7.3K Forum Archives
Check out the Formula Handbook template!