Nested IF statement for multiple date range
Hello! I am currently attempting to write an all encompassing formula to read through different work windows. We are only able to work in certain areas of the city depending on the "work window". Depending on the work window, these dates have differing start and end dates. I can get one window to work properly, but the logic seems to fall apart or just does not parse when adding in different work windows. The formula for one window is below:
=IF(AND(Date@row >= DATE(2024, 7, 16), Date@row <= DATE(2025, 3, 15), [Work Window]@row = "A : 07/16 - 03/15"), "", 1)
(If a date is outside of 7/16/2024 and 3/15/2025, this cell is flagged as it is outside the work window)
My question is, how do I nest these so the logic makes sense? It would need to read each individual work window, and then filter through the dates manually as we are just using a String for the actual "work window". Logically, I feel like this should work but between the ANDs and ORs I think it falls apart.
The cell that is labeled "works" contains this formula. The same with the rows below it, which is flagging as the dates are outside the aforementioned work window.
Image attached! Any guidance would be huge!!!
Best Answer
-
Hi Justin, You can certainly build a massive formula with nested IFs, but I suspect that will be tough to debug. And, I don't know how many Work Windows you would have so it would be unwieldy too.
A better way to solve this would be to create a reference sheet with the Work Window in the first column and columns for the "start date" and "end date". This sheet could have any number of Work Windows.
Then, to keep things as easy to understand as possible, I would add two helper date columns in your main sheet, one for the start date and one for the end date. You would then use cross sheet references and the INDEX(MATCH) functions to bring the start date and end date from the reference sheet into your main sheet based on the Work Window indicated in the main sheet. You could hide these columns if you don't want to see them.
Then you could construct your same IF statement using AND() to see if the date is after the start date and before the end date.
I hope this helps.
Be well
If my response was helpful or answered your question please be sure to upvote it, mark it asawesome, or mark it as the accepted answer!
Answers
-
Hi Justin, You can certainly build a massive formula with nested IFs, but I suspect that will be tough to debug. And, I don't know how many Work Windows you would have so it would be unwieldy too.
A better way to solve this would be to create a reference sheet with the Work Window in the first column and columns for the "start date" and "end date". This sheet could have any number of Work Windows.
Then, to keep things as easy to understand as possible, I would add two helper date columns in your main sheet, one for the start date and one for the end date. You would then use cross sheet references and the INDEX(MATCH) functions to bring the start date and end date from the reference sheet into your main sheet based on the Work Window indicated in the main sheet. You could hide these columns if you don't want to see them.
Then you could construct your same IF statement using AND() to see if the date is after the start date and before the end date.
I hope this helps.
Be well
If my response was helpful or answered your question please be sure to upvote it, mark it asawesome, or mark it as the accepted answer!
-
Hi Scott,
We're cooking for now, I appreciate the help!!
Help Article Resources
Categories
- All Categories
- 14 Welcome to the Community
- Smartsheet Customer Resources
- 63.9K Get Help
- 410 Global Discussions
- 220 Industry Talk
- 458 Announcements
- 4.8K Ideas & Feature Requests
- 143 Brandfolder
- 136 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!