0

I dived into a nested if statement and it's now way over my head. Could you please take a look and let me know why it doesn't work?

All I wantis to categorize our accounts based on multiple criteria. Region, Sector and later on the number of employees. But i've been at it for 2 hours to no avail...

IF(
ISPICKVAL( Sector__c, "Supplier/Distributor"), "Supplier", 
IF(
ISPICKVAL( Account_Region__c , "Middle East"), "Middle East",
  IF(
    ISPICKVAL( Account_Region__c , "Americas"), 
      IF(BEGINS(TEXT(Sector__c) , "Restaurants")), "US Restaurants", "US Hotels")))

The error message reads:

Error: Incorrect number of parameters for function 'IF()'. Expected 3, received 1

Many thanks in advance!

Csongor

  • 1
    Can you add more details on your objective? The formula looks valid, as it is. Are you trying to concatenate values from several different fields? – David Reed May 24 '18 at 16:15
  • Not event that - it's a simple formula(text) field that will say various things depending on the picklist values. – Csongor May 24 '18 at 16:17
  • 1
    So how is it currently failing? Can you edit your question to add those details? – David Reed May 24 '18 at 16:18
  • ah, good point! – Csongor May 24 '18 at 16:27
4

You had a spurious parenthesis resulting in closing an IF too early. I think this is what you're aiming at here (note the comment, which you shouldn't include in your formula):

IF(
    ISPICKVAL(Sector__c, "Supplier/Distributor"), 
    "Supplier", 
    IF(
        ISPICKVAL(Account_Region__c , "Middle East"), 
        "Middle East",
        IF(
            ISPICKVAL(Account_Region__c , "Americas"), 
            IF(
                BEGINS(TEXT(Sector__c) , "Restaurants"), // Spurious parenthesis was here 
                "US Restaurants", 
                "US Hotels"
            ), 
            "" // Note we need another parameter here
        )
    )
)
| improve this answer | |
  • Thanks David, I'm afraid I still get the following error message after copying your quote without the comments of course: "Error: Incorrect number of parameters for function 'IF()'. Expected 3, received 2" – Csongor May 24 '18 at 16:33
  • Whoops, I missed that. See my edit. You need a default value for if the account's not in the Americas. – David Reed May 24 '18 at 16:35
  • ABSOLUTELY BRILLIANT! Thank you David, much much appreciated!!! – Csongor May 24 '18 at 16:37
  • Hey David, if you have some time, could you please look at my final piece of the puzzle? Same task, just additional spurious parentheses... Many thanks, Cs salesforce.stackexchange.com/questions/219391/… – Csongor May 25 '18 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.