Nested IF & Multiple arguments
Hey there!
Currently trying to automate a tracking report that my company uses. I want the "District" column to automate based on the property number entered. However, while there is only 7 districts, the list of properties could easily be in the thousands. We can determine the district of a property by the first two digits, so I started with a LEFT statement, to pull those two digits out. I then tried to create a nested IF statement that looks like this:
=IF([LEFT Function]1 = "01", "4", IF([LEFT Function]1 = "02", "2", IF([LEFT Function]1 = "03", "1", IF([LEFT Function]1 = "04", "5", IF([LEFT Function]1 = "05", "6", IF([LEFT Function]1 = "06", "1", IF([LEFT Function]1 = "07", "7", IF([LEFT Function]1 = "08", "7", IF([LEFT Function]1 = "09", "7", IF([LEFT Function]1 = "10", "4"))))))))))
On this small of a scale, it worked wonderfully. However, there are a total of sixty-two 2-digit codes that need to be in the IF statement for this automation to work across the board. I tried writing out the full 62 IF statements in a long string by copy & pasting the string that worked and just modifying the values, but it came back #UNPARSEABLE.
Is it because i have too many arguments? Has anyone else tried an IF statement on this scale, or know of any other way to work this out?
Comments
-
I'm not sure if there are limitations on arguments, but the slightest error can mess it up. I've seen UNPARSEABLE in the following cases:
- when I used a word processor to create the formula. It autocorrected my straight quotes into smart quotes which messes with Smartsheet formulas. Always use a simple text editor.
- When I didn't have the right number of closing parenthesis. There is a little trick I learned from another community member to delete all the closing parenthesis at the end of the formula. Smartsheet will close them all for you. No need to count.
- Also, any misspellings on the column names can throw an unparseable.
If you want to share the formula I can quickly scan it for you for anything I can see.
-
Using nested IF statements does not scale well. Instead you should use a VLOOKUP function to do the decoding. I've attached a screenshot that shows the formula you would need
-
I am going to second Andrew's suggestion. The only thing I would add is that you may need to use VALUE(LEFT(..............., 2), ...................................) depending on how your table is built.
-
Yes, I agree with them, a vlookup would allow you to keep a list that you could edit and manage outside of each individual formula. Which would be far easier to maintain. You could also do Vlookup with a cross-sheet reference.
-
Thank you! I will follow the VLOOKUP recommendation below, but I appreciate the offer to look it over for me. I will also keep in mind your suggestion to stick to simple text editors in the future so I can hopefully avoid this error.
-
I appreciate it! I wasn't sure how large I could scale an IF statement so this helps me a lot. I will try the VLOOKUP with the above formula - thank you!
-
The only limitations to the scaling would be the 4,000 characters per cell limit. Otherwise you can have as many IF statements strung together as you need. It may not be very user friendly after a certain point, but there isn't a limit as to how many functions you nest together.
-
Out of curiosity, I reviewed my nested if statement with 62 arguments - found ONE smart quote. Fixed it and now the whole statement works! awesome
-
62?!? You are a braver soul than I. Hahaha. Once I get past 3 or 4 I move it to a table.
-
It's a shame that one small thing like that upsets the whole apple cart. Glad you were able to get working. That is a beast of an if-statement. I've created several like it in my day. Good job and good luck maintaining that beast!
Help Article Resources
Categories
- All Categories
- 14 Welcome to the Community
- Smartsheet Customer Resources
- 64.3K Get Help
- 423 Global Discussions
- 221 Industry Talk
- 462 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!