Avoiding a massive nested IF formula - checkboxes?
Hi all,
I have 5 check boxes and based on these being ticked or unticked i want to display something in another cell.
It is essentially a decision tree that simply i want to work as follows:
If Group 2 is not ticked (or nothing ticked) = Group 1
If Group 2 is ticked but 3, 4, 5 & Close are not = Group 2
If Groups 2 & 3 are ticked but 4, 5 & Close are not = Group 3
If Groups 2, 3 & 4 are ticked but 5 and close are not = Group 4
If Groups 2, 3, 4 & 5 are ticked but close is not = Group 5
If Group 2, 3, 4, 5 & Close are ticked (all are ticked) = Close
Any ways of doing this simpler than building in every possible scenario via nested IFs? It is a linear structure in that 3 will not be ticked before 2 for example which i know avoids me having to do every combination.
Any help is much appreciated.
Thanks,
Jack
Best Answer
-
Work backwards with your IF statements. Nested IFs stop on the first true value, so if it makes it to the next one, then the previous IF(s) MUST be false.
=IF(Close@row = 1, "Close",
Starting with this means that everything that follows automatically assumes that Close@row is NOT checked.
=IF(Close@row = 1, "Close", IF([Group 5]@row = 1, "Group 5",
Anything coming after this portion automatically assumes that Close@row and [Group 5]@row are both unchecked. So we continue with this logic that "if it has made it this far then everything before it must be false" and work (almost) the rest of your requirements in using the same logic.
=IF(Close@row = 1, "Close", IF([Group 5]@row = 1, "Group 5", IF([Group 4]@row = 1, "Group 4", IF([Group 3]@row = 1, "Group 3", IF([Group 2]@row = 1, "Group 2",
Now that we only have one option left (because to get this far everything prior must be false which means all of those boxes are unchecked), we can just use the "if false" portion of the final IF statement to say that if everything prior is false, "Group 1". Then we close out all of the IF statements all at once and your formula is complete.
=IF(Close@row = 1, "Close", IF([Group 5]@row = 1, "Group 5", IF([Group 4]@row = 1, "Group 4", IF([Group 3]@row = 1, "Group 3", IF([Group 2]@row = 1, "Group 2", "Group 1")))))
Answers
-
Work backwards with your IF statements. Nested IFs stop on the first true value, so if it makes it to the next one, then the previous IF(s) MUST be false.
=IF(Close@row = 1, "Close",
Starting with this means that everything that follows automatically assumes that Close@row is NOT checked.
=IF(Close@row = 1, "Close", IF([Group 5]@row = 1, "Group 5",
Anything coming after this portion automatically assumes that Close@row and [Group 5]@row are both unchecked. So we continue with this logic that "if it has made it this far then everything before it must be false" and work (almost) the rest of your requirements in using the same logic.
=IF(Close@row = 1, "Close", IF([Group 5]@row = 1, "Group 5", IF([Group 4]@row = 1, "Group 4", IF([Group 3]@row = 1, "Group 3", IF([Group 2]@row = 1, "Group 2",
Now that we only have one option left (because to get this far everything prior must be false which means all of those boxes are unchecked), we can just use the "if false" portion of the final IF statement to say that if everything prior is false, "Group 1". Then we close out all of the IF statements all at once and your formula is complete.
=IF(Close@row = 1, "Close", IF([Group 5]@row = 1, "Group 5", IF([Group 4]@row = 1, "Group 4", IF([Group 3]@row = 1, "Group 3", IF([Group 2]@row = 1, "Group 2", "Group 1")))))
-
Thank you Paul, that perfect.
Jack
-
Happy to help! 👍️
Help Article Resources
Categories
- All Categories
- 14 Welcome to the Community
- Smartsheet Customer Resources
- 64.4K Get Help
- 424 Global Discussions
- 221 Industry Talk
- 463 Announcements
- 4.8K Ideas & Feature Requests
- 143 Brandfolder
- 144 Just for fun
- 59 Community Job Board
- 463 Show & Tell
- 32 Member Spotlight
- 1 SmartStories
- 300 Events
- 39 Webinars
- 7.3K Forum Archives
Check out the Formula Handbook template!