-3

if( CONTAINS("206:209:213:253:310:323:360:408:415:425:503:509:510:530:559:562:604:619:626:650:661:702:707:714:760:775:778:805:818:831:858:867:909:916:925:949:951:971:236:250:604:778:867", left(SUBSTITUTE( Phone , "(", ""),3)),"UTC-7 Pacific",

if(

CONTAINS("208:250:303:307:385403:406:435:480:505:520:602:623:719:720:780:801:928:970:403:587:780", left(SUBSTITUTE( Phone , "(", ""),3)),"UTC-6 Mountain",

if(

CONTAINS("808", left(SUBSTITUTE( Phone , "(", ""),3)),"UTC-10 US/Hawaii",

if(

CONTAINS("907", left(SUBSTITUTE( Phone , "(", ""),3)),"UTC-8 US/Alaska",

if(

CONTAINS("204:205:210:214:217:218:224:225:228:251:254:256:262:270:281:306:308:309:312:314:316:318:319:320:325:334:337:361:402:405:409:414:417:430:432:469:479:501:504:507:512:515:563:573:580:601:605:608:612:615:618:620:630:636:641:651:660:662:682:708:712:713:715:731:763:769:773:785:806:815:816:817:830:832:847:901:903:913:915:918:920:931:936:940:952:956:972:979:985:204:306:431:639:807", left(SUBSTITUTE( Phone , "(", ""),3)),"UTC-5 Central",

if(

CONTAINS("201:202:203:207:212:215:216:219:226:229:231:234:239:240:248:252:267:269:276:289:301:302:304:305:313:315:321:330:336:339:345:347:351:352:386:404:407:410:412:416:418:419:434:438:440:443:450:470:475:478:484:502:508:513:514:516:517:518:519:540:551:561:567:570:571:585:586:603:606:607:609:610:613:614:616:617:631:646:647:649:678:703:704:705:706:716:717:718:724:727:732:734:740:754:757:770:772:774:781:786:802:803:804:810:813:814:819:828:835:843:845:848:856:857:859:860:862:863:864:865:876:878:904:905:908:910:912:914:917:919:937:941:947:954:959:973:978:980:226:249:289:343:365:416:437:438:450:514:519:579:581:613:647:705:819:873:905", left(SUBSTITUTE( Phone , "(", ""),3)),"UTC-4 Eastern",

if(

CONTAINS("506:709:902",LEFT(SUBSTITUTE(Phone,"(",""),3)),"UTC-3 Atlantic",

if(

CONTAINS("800:877",LEFT(SUBSTITUTE(Phone,"(",""),3)),"Toll Free","Other",

IF(CONTAINS("American Samoa", Country ), "UTC-11 American Samoa",

IF(CONTAINS("Mexico", Country ), "UTC-7 US/Pacific",

IF(CONTAINS("Belize,Chile,Costa Rica,El Salvador,Guatemala,Honduras,Nicaragua", Country ), "UTC-6 US/Mountain",

IF(CONTAINS("Brazil,Cayman Islands,Colombia,Ecuador,Jamaica,Panama,Peru", Country ), "UTC-5 America/Panama",

IF(CONTAINS("Cuba,Dominican Republic,Puerto Rico,Virgin Islands,Venezuela,Bahamas,Curacao", Country ), "UTC-3 America/Argentina",

IF(CONTAINS("Argentina,Uruguay,Bermuda", Country ), "UTC-3 America/Argentina",

IF(CONTAINS("Portugal,Ghana", Country ), "UTC +00:00 Azores",

IF(CONTAINS("United Kingdom,London,England,Wales,Scotland,Ireland,Algeria,Morocco,Nigeria", Country ), "UTC +1 Europe/London",

IF(CONTAINS("Croatia,Denmark,France,Germany,Hungary,Italy,Netherlands,Norway,Poland,South Africa,Spain,Sweden,Switzerland,Austria,Botswana,Egypt,Zambia", Country ), "UTC +2 Europe/Amsterdam",

IF(CONTAINS("Bulgaria,Finland,Greece,Iraq,Israel,Kenya,Romania,Syria,Turkey,Ukraine,Yemen,Russia,Cyprus,Ethiopia,Jordan,Kuwait,Saudi Arabia,Tanzania", Country ), "UTC +3 Europe/Moscow",

IF(CONTAINS("Oman,United Arab Emirates,UAE", Country ), "UTC +4 Asia/Muscat",

IF(CONTAINS("Pakistan", Country ), "UTC +5 Asia/Karachi",

IF(CONTAINS("Sri Lanka,India", Country ), "UTC+5.5 Asia/India",

IF(CONTAINS("Kazakhstan,Bangladesh", Country ), "UTC+6 Asia/Almaty",

IF(CONTAINS("Cambodia,Vietnam,Thailand,Indonesia", Country ), "UTC+7 Asia/Bangkok",

IF(CONTAINS("China,Taiwan,Hong Kong,Philippines,Singapore,Malaysia", Country ), "UTC+8 Asia/Hong Kong",

IF(CONTAINS("Japan,North Korea,South Korea", Country ), "UTC+9 Asia/Tokyo",

IF(CONTAINS("Australia,Guam,Papua New Guinea", Country ), "UTC+10 Australia/Sydney",

IF(CONTAINS("New Zealand", Country ), "UTC+12 Pacific/Auckland",

IF(ISBLANK(Country),NULL,"--"))))))))))))))))))))))))))))

2
  • 1
    I'd normally advise to format your formula properly (i.e. like code, with each "statement" going on its own line, and indenting an additional level when you encounter another open paren), but this one is so massive that it wouldn't be that much easier to read (and you'd probably run into the character limit for SFSE). That said, the error is clear. It's just a matter of filtering through that mass of text to see where you made a mistake. In this case, that'd be an extra comma between the end of your CONTAINS() and the next IF().
    – Derek F
    May 22 at 19:50
  • When building complex formulas, you definitely want to use a professional text editor (Notepad++, Sublime, etc) that has bracket/brace highlighting to help you identify missing or extra closing parentheses. Also - you may exceed the formula character limit with something this large. May 22 at 20:18

2 Answers 2

1

Well, in trying to format that moster you have there, the first issue I saw was about 1/3 of the way into the formula.

With some helpful comments added and proper formatting

IF(
    /* logical test */
    CONTAINS("800:877", LEFT(SUBSTITUTE(Phone,"(",""), 3)),
    /* value if true */
    "Toll Free",
    /* This is an extra value, the thing causing your issue */
    "Other",
    /* Next IF in the IF-ELSE IF chain */
    IF(
        CONTAINS("American Samoa", Country),
        ...

This may not be the only issue (I'd be surprised if this managed to fit within the character and compiled size limits for formulas), but it's the issue the error is complaining about.

As the error says, IF() takes 3 parameters (each separated with a comma), so if you see more than two commas between the end of your CONTAINS() and the next IF(), then you've made a mistake. Regex can help in finding a pattern like that. The one I worked out (given the formatting you've used here) is \),(".*",){2,}\n{1,2}IF, which appears to only have one match.

0

I decided to reorder to the conditions to be easier to read. You had an extra parentheses on the left(substitute(phone, "(", ""), 3))). You also had an if statement that was messed up as a result of this. After untangling all of this, the "--" option didn't seem to fit anywhere, so I left it out. Here's the resulting formula:

if( ISBLANK(Country), NULL, 
if( CONTAINS("American Samoa", Country), "UTC-11 American Samoa", 
if( CONTAINS("Mexico", Country  ), "UTC-7 US/Pacific", 
if( CONTAINS("Belize,Chile,Costa Rica,El Salvador,Guatemala,Honduras,Nicaragua", Country ), "UTC-6 US/Mountain", 
if( CONTAINS("Brazil,Cayman Islands,Colombia,Ecuador,Jamaica,Panama,Peru", Country ), "UTC-5 America/Panama", 
if( CONTAINS("Cuba,Dominican Republic,Puerto Rico,Virgin Islands,Venezuela,Bahamas,Curacao", Country ), "UTC-3 America/Argentina", 
if( CONTAINS("Argentina,Uruguay,Bermuda", Country ), "UTC-3 America/Argentina", 
if( CONTAINS("Portugal,Ghana", Country ), "UTC +00:00 Azores", 
if( CONTAINS("United Kingdom,London,England,Wales,Scotland,Ireland,Algeria,Morocco,Nigeria", Country ), "UTC +1 Europe/London", 
if( CONTAINS( "Croatia,Denmark,France,Germany,Hungary,Italy,Netherlands,Norway,Poland,South Africa,Spain,Sweden,Switzerland,Austria,Botswana,Egypt,Zambia", Country ), "UTC +2 Europe/Amsterdam", 
if( CONTAINS( "Bulgaria,Finland,Greece,Iraq,Israel,Kenya,Romania,Syria,Turkey,Ukraine,Yemen,Russia,Cyprus,Ethiopia,Jordan,Kuwait,Saudi Arabia,Tanzania", Country ), "UTC +3 Europe/Moscow", 
if( CONTAINS("Oman,United Arab Emirates,UAE", Country ), "UTC +4 Asia/Muscat", 
if( CONTAINS("Pakistan", Country ), "UTC +5 Asia/Karachi", 
if( CONTAINS("Sri Lanka,India", Country ), "UTC+5.5 Asia/India", 
if( CONTAINS("Kazakhstan,Bangladesh", Country ), "UTC+6 Asia/Almaty", 
if( CONTAINS("Cambodia,Vietnam,Thailand,Indonesia", Country ), "UTC+7 Asia/Bangkok", 
if( CONTAINS("China,Taiwan,Hong Kong,Philippines,Singapore,Malaysia", Country ), "UTC+8 Asia/Hong Kong", 
if( CONTAINS("Japan,North Korea,South Korea", Country ), "UTC+9 Asia/Tokyo", 
if( CONTAINS("Australia,Guam,Papua New Guinea", Country ), "UTC+10 Australia/Sydney", 
if( CONTAINS("New Zealand", Country ), "UTC+12 Pacific/Auckland", 
if( CONTAINS( "206:209:213:253:310:323:360:408:415:425:503:509:510:530:559:562:604:619:626:650:661:702:707:714:760:775:778:805:818:831:858:867:909:916:925:949:951:971:236:250:604:778:867", left(SUBSTITUTE( Phone , "(", ""),3) ), "UTC-7 Pacific", 
if( CONTAINS( "208:250:303:307:385403:406:435:480:505:520:602:623:719:720:780:801:928:970:403:587:780", left(SUBSTITUTE( Phone , "(", ""),3) ), "UTC-6 Mountain", 
if( CONTAINS("808", left(SUBSTITUTE( Phone , "(", ""),3)), "UTC-10 US/Hawaii", 
if( CONTAINS("907", left(SUBSTITUTE( Phone , "(", ""),3)), "UTC-8 US/Alaska", 
if( CONTAINS( "204:205:210:214:217:218:224:225:228:251:254:256:262:270:281:306:308:309:312:314:316:318:319:320:325:334:337:361:402:405:409:414:417:430:432:469:479:501:504:507:512:515:563:573:580:601:605:608:612:615:618:620:630:636:641:651:660:662:682:708:712:713:715:731:763:769:773:785:806:815:816:817:830:832:847:901:903:913:915:918:920:931:936:940:952:956:972:979:985:204:306:431:639:807", left(SUBSTITUTE( Phone , "(", ""),3) ), "UTC-5 Central", 
if( CONTAINS( "201:202:203:207:212:215:216:219:226:229:231:234:239:240:248:252:267:269:276:289:301:302:304:305:313:315:321:330:336:339:345:347:351:352:386:404:407:410:412:416:418:419:434:438:440:443:450:470:475:478:484:502:508:513:514:516:517:518:519:540:551:561:567:570:571:585:586:603:606:607:609:610:613:614:616:617:631:646:647:649:678:703:704:705:706:716:717:718:724:727:732:734:740:754:757:770:772:774:781:786:802:803:804:810:813:814:819:828:835:843:845:848:856:857:859:860:862:863:864:865:876:878:904:905:908:910:912:914:917:919:937:941:947:954:959:973:978:980:226:249:289:343:365:416:437:438:450:514:519:579:581:613:647:705:819:873:905", left(SUBSTITUTE( Phone , "(", ""),3) ), "UTC-4 Eastern", 
if( CONTAINS("506:709:902",LEFT(SUBSTITUTE(Phone,"(",""),3)), "UTC-3 Atlantic", 
if( CONTAINS("800:877",LEFT(SUBSTITUTE(Phone,"(",""),3)), "Toll Free", "Other" ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )

This may fail to compile for other reasons, but this looks fairly reasonable.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .