Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
117 views
in Technique[技术] by (71.8m points)

ex - Excel 2013 - "too many arguments" message to IFAND formula

I am creating a decision tool where yes/no responses will trigger a follow up question or decision. I created a formula with 13 arguments where each IF has two AND conditions (if no - it is true, if yes - It is false). I am no expert and tried to follow the guidance from several tutorials and help sites. This is my formula:

=IF((AND(J7="Planned - Shift / Vacation Coverage", M7="No")), "Is an E out?", "Schedule LE", 
IF((AND(J7="Planned - Off-shift PMs", M7="No")), "Can the scheduled resources complete work within shift?", "CE reassigns WOs to new shift LE - No OT needed", 
IF((AND(J7="Planned - Customer driven shutdown", M7="No")), "Schedules OT", "CE assigns work to LEs", 
IF((AND(J7="Planned - Training", M7="No")), "Schedules OT", "Does LE need to get trained in OT?", 
IF((AND(J7="Planned - Customer event", M7="No")), "Schedules OT", "CE assigns work to LE", 
IF((AND(J7="Unplanned - Sick call in", M7="No")), "Is an E out?", "Schedules LE", 
IF((AND(J7="Unplanned - Escorting", M7="No")), "Schedule OT", "Move scheduled work to next day/week", 
IF((AND(J7="Unplanned - Emergency response/repair", M7="No")), "Is the request a code 3?", "Can this be handled by scheduled resources?", 
IF((AND(J7="Unplanned - Customer Event", M7="No")), "Schedules OT", "Executes work within shift", 
IF((AND(J7="Unplanned - Call in", M7="No")), "OT will not be paid", "Schedules OT", 
IF((AND(J7="Unplanned - Weather", M7="No")), "Can resources be allocated from the shift in the first instance?", "Can CE or ACE become the additional HC?", 
IF((AND(J7="Planned - Off premises work", M7="No")), "Schedules OT", "LE schedules time off premises within shift", 
IF((AND(J7="Administrative work", M7="No")), "Schedules OT", "Executes within shift")))))))))))))

What did I do wrong??? Please HELP!!!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The problem with your if statement is you are trying to do more than two things. An IF formula has three parts

  • logical test
  • What to do if logical is true
  • What to do if logical is false

in terms of a formula layout it looks like this:

=IF(Logical Test, What to do if True, What to do if false)

notice that between the () there are only 3 things each separated by a total of two comas. Now in order to nest IF formulas, you need to put follow up IF formulas in the what to do if True or the what to do if False. You can put one in each if you like. Each subsequent IF formula will have its one what to do if true/false parts. I will add 1 and 2 to the IF formula for demonstration purposes, it is not proper syntax:

=IF1(Logical test1, What to do if True1, IF2(Logical test2, What to do if True2, What to do if False2))

The only way IF2 is checked, is if the logical test in in the first if returns false.

Now if we look at your first if statement, ignoring the close bracket way at te end. We have:

IF((AND(J7="Planned - Shift / Vacation Coverage", M7="No")), "Is an E out?", "Schedule LE", 

The logical test is:

(AND(J7="Planned - Shift / Vacation Coverage", M7="No")

Nothing technically wrong with the logical test, but you do not need the () around the and statement. eliminating them may make things easier to read and keep tract of the bracket count. I would have just used:

AND(J7="Planned - Shift / Vacation Coverage", M7="No"

Another thing I just noted with your logical test, is that every single one of them is checking M7 to see if it is NO. Rather than placing an and check with each if statement always checking the same result, you could put the M7 check way out front in an if formula, and then check each subsequent value for J7 either just the true or just the false path of the first if statement:

=IF(M7<>"NO","What to do when M7 is yes",
IF(J7="Planned - Shift / Vacation Coverage",.....

Your what to do if true part is:

"Is an E out?"

Your what to do if false part is:

"Schedule LE"

nothing wrong with either of those two results being presented. The problem is right after your what to do if false part you put another coma. The IF formula does not know how to deal with anything beyond that the second and this coma after the false result is the 3rd comma for that if statement.

I would recommend you start building a simple if statement without any nesting and get it to work for one case. When you have this working for one case, toss in your second case and nest the IF statement and get it working. once you get it working toss in your third case and get it working. Hopefully by about the 3rd or 4th case a pattern will emerge. follow the pattern up until you have all your cases covered. if you do not see the pattern, then just add on one case at a time until you have everything covered.

one of the problems you are facing with your IF statements is you need a way to determine whether statement 1 or statement 2 should be displayed when your logical check is true, and assume when your logical check is false you want to move on to your next IF formula check. Below I have attempted to guess at a partial process of your if statements by adding an embedded IF to check the value of some other column to decided what to do in your decision making. I have referred to cell AA, AB, AC etc to make them easier to spot:

=IF(M7<>"NO","What to do when M7 is yes",
IF(J7="Planned - Shift / Vacation Coverage",IF(AA7="", "Is an E out?", "Schedule LE"),
IF(J7="Planned - Off-shift PMs", IF(AB7="","Can the scheduled resources complete work within shift?", "CE reassigns WOs to new shift LE - No OT needed"),
IF(J7="Planned - Customer driven shutdown",IF(AC7="","Schedules OT", "CE assigns work to LEs"),
IF(J7="Planned - Training", IF(AD7="","Schedules OT", "Does LE need to get trained in OT?"),
IF(J7="Planned - Customer event",IF(AE7="", "Schedules OT", "CE assigns work to LE"),
IF(J7="Unplanned - Sick call in", IF(AF7="","Is an E out?", "Schedules LE"))))))))

With out seeing your decision tree or spreadsheet it is difficult to help you out with the process. Again I would recommend starting off small with a basic IF statement and then building from there.

Another thing that may help you out is to draw out a decision tree on paper. The first question is your first if formula. Each question can only have two results. True or False. So you draw a true line and at the end of the true line you either display text, or ask another question. Do the same for the false line. If you ask another question, that is another IF formula, and your draw two line from that question. Keep this process up until you have no mor questions.

Binary Decision Tree

Search for Binary Decision Tree to learn more about this topic. The following decision tree example is not binary as the first choice has more than two possible results. Similar to what it appears you are trying to do. As such, the IF statement cannot work with the three or more choices at the top level. The decision tree would need to be modified to make it work with the IF statement.

Non binary decision tree


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...