Forum Discussion

eilidh3's avatar
eilidh3
Frequent Visitor
6 years ago
Solved

Too many arguments were passed to the IF function.

Im looking to create a new column with short form of our business names.  We have 22 business units.  I have tried the below however it wont allow me and comes up with the following error ' Too many arguments were passed to the IF function.  The maximum argument count for the function is 3.

 

My DAX code is as follows:

 

Business Unit NEW = IF([Business Unit] = "Civil Engineering" || [Business Unit] = "Civil Engineering Small Works","Civils", IF([Business Unit] = "Construction Central" || [Business Unit] = "Construction Small Works Central", "Central ", IF([Business Unit] = "Construction West" || "Robertson Construction Small Works West", "West", IF([Business Unit]="Construction Group", "Group", IF([Business Unit] = "Construction East" || "Construction Small Works East", "East", IF([Business Unit] = "Construction North" || "Construction Small Works North", "North", IF([Business Unit] = "Construction Northern", "Construction Small Works Northern", "Northern", IF([Business Unit]= "Engineering Services", "M&E", IF([Business Unit] = "Facilities Management", "FM", IF([Business Unit] = "Partnership Homes", "Homes", IF([Business Unit] = "Specialist Division", "Specialist")
 
Any help anyone can give would be much appreciated.
 
Thanks
  • Hi eilidh3 

    Your statement will feel itself better if you try such

    IF([Business Unit] = "Civil Engineering" || [Business Unit] = "Civil Engineering Small Works","Civils", 
    IF([Business Unit] = "Construction Central" || [Business Unit] = "Construction Small Works Central", "Central ", 
    IF([Business Unit] = "Construction West" || [Business Unit] = "Robertson Construction Small Works West", "West", 
    IF([Business Unit]= "Construction Group", "Group", 
    IF([Business Unit] = "Construction East" || [Business Unit] = "Construction Small Works East", "East", 
    IF([Business Unit] = "Construction North" || [Business Unit] = "Construction Small Works North", "North", 
    IF([Business Unit] = "Construction Northern"|| [Business Unit] = "Construction Small Works Northern", "Northern", 
    IF([Business Unit]= "Engineering Services", "M&E", 
    IF([Business Unit] = "Facilities Management", "FM", 
    IF([Business Unit] = "Partnership Homes", "Homes", 
    IF([Business Unit] = "Specialist Division", "Specialist"
    )))))))))))

     

    But the best option is using switch

    SWITCH([Business Unit],
    "Civil Engineering", "Civils",
    "Civil Engineering Small Works","Civils", 
    "Construction Central", "Central ", 
    "Construction Small Works Central", "Central ", 
    "Construction West", "West",
    "Robertson Construction Small Works West", "West", 
    "Construction Group", "Group", 
    "Construction East", "East", 
    "Construction Small Works East", "East", 
    "Construction North", "North", 
    "Construction Small Works North", "North", 
    "Construction Northern", "Northern", 
    "Construction Small Works Northern", "Northern", 
    "Engineering Services", "M&E", 
    "Facilities Management", "FM", 
    "Partnership Homes", "Homes", 
    "Specialist Division", "Specialist",
    "Undefined"
    )

     

    do not hesitate to give a kudo to useful posts and mark solutions as solution

    LinkedIn

5 Replies

  • az38's avatar
    az38
    Icon for Community Champion rankCommunity Champion

    Hi eilidh3 

    Your statement will feel itself better if you try such

    IF([Business Unit] = "Civil Engineering" || [Business Unit] = "Civil Engineering Small Works","Civils", 
    IF([Business Unit] = "Construction Central" || [Business Unit] = "Construction Small Works Central", "Central ", 
    IF([Business Unit] = "Construction West" || [Business Unit] = "Robertson Construction Small Works West", "West", 
    IF([Business Unit]= "Construction Group", "Group", 
    IF([Business Unit] = "Construction East" || [Business Unit] = "Construction Small Works East", "East", 
    IF([Business Unit] = "Construction North" || [Business Unit] = "Construction Small Works North", "North", 
    IF([Business Unit] = "Construction Northern"|| [Business Unit] = "Construction Small Works Northern", "Northern", 
    IF([Business Unit]= "Engineering Services", "M&E", 
    IF([Business Unit] = "Facilities Management", "FM", 
    IF([Business Unit] = "Partnership Homes", "Homes", 
    IF([Business Unit] = "Specialist Division", "Specialist"
    )))))))))))

     

    But the best option is using switch

    SWITCH([Business Unit],
    "Civil Engineering", "Civils",
    "Civil Engineering Small Works","Civils", 
    "Construction Central", "Central ", 
    "Construction Small Works Central", "Central ", 
    "Construction West", "West",
    "Robertson Construction Small Works West", "West", 
    "Construction Group", "Group", 
    "Construction East", "East", 
    "Construction Small Works East", "East", 
    "Construction North", "North", 
    "Construction Small Works North", "North", 
    "Construction Northern", "Northern", 
    "Construction Small Works Northern", "Northern", 
    "Engineering Services", "M&E", 
    "Facilities Management", "FM", 
    "Partnership Homes", "Homes", 
    "Specialist Division", "Specialist",
    "Undefined"
    )

     

    do not hesitate to give a kudo to useful posts and mark solutions as solution

    LinkedIn

  • HotChilli's avatar
    HotChilli
    Icon for Community Champion rankCommunity Champion

    There are quite a few places in the statement where it stops explicitly testing against the column e.g.

    IF([Business Unit] = "Construction East" || "Construction Small Works East", "East"

     

    the code needs to do tests as in the first line.

     

     

    Also check out the switch statement to save typing.

  • You use way too many arguments indeed. You have 3 parameters, the first one being what is tested, the second one if the first resolves to true, and the third if it resolves to false. So you will either need to use nesting if's, or the switch as shown above.

  • eilidh3's avatar
    eilidh3
    Frequent Visitor

    Thank you all for your help.  Ive never used SWITCH before but it was very easy!!