如果语句 - 多个是/否列条件简化了不断增长的嵌套 IF AND 公式?

如果语句 - 多个是/否列条件简化了不断增长的嵌套 IF AND 公式?

我正在研究一个 Excel 问题,该问题根据多个 (3) 是/否列的条件答案填充单独的列。具体来说,我正在尝试使用选项组合。这 3 个选项:

  • 中央世界
  • 柔性
  • 远程

您可以选择其中 1 个、2 个或全部 3 个选项。

我的工作表:

我的截图

我的代码不太优雅地解决了我的问题。

=IF(AND(B2="NO",B2=C2,B2=D2),"NO-FLEX",IF(AND(B2="YES",B2=C2,B2=D2),"Full match",IF(AND(B2="Yes",C2="Yes"),"CWW-FLEX",IF(AND(B2="Yes",D2="Yes"),"CWW-TELE",IF(AND(C2="Yes",D2="Yes"),"FLEX-TELE",IF(AND(B2="NO",C2="NO"),"TELE-ONLY",IF(AND(B2="NO",D2="NO"),"FLEX-ONLY",IF(AND(C2="NO",D2="NO"),"CWW-ONLY",IF(AND(B2="YES",C2="",D2=""),"CWW-ONLY",IF(AND(C2="YES",B2="",D2=""),"FLEX-ONLY",IF(AND(D2="YES",B2="",C2=""),"TELE-ONLY",IF(AND(B2="NO",C2="YES",D2=""),"FLEX-ONLY",IF(AND(B2="NO",C2="",D2="YES"),"TELE-ONLY",IF(AND(D2="NO",B2="",C2="YES"),"FLEX-ONLY",IF(AND(B2="",C2="NO",D2="YES"),"TELE-ONLY",IF(AND(B2="YES",C2="",D2="NO"),"CWW-ONLY",IF(AND(B2="YES",C2="NO",D2=""),"CWW-ONLY",)))))))))))))))))

到目前为止,我已经成功地创建了一个大型IF(AND)语句,在大多数情况下,该语句会根据选择的组合用正确的指标填充一列。

这个解决方案并不优雅,可能有办法简化我不断增长的嵌套IF(AND)公式。有人能帮忙吗?非常感谢任何建议。

答案1

我认为最好的方法是使用以下CHOOSE()功能:

=CHOOSE(1+1*(UPPER(B2)="YES")+2*(UPPER(C2)="YES")+4*(UPPER(D2)="YES"),"n/a","CWW-ONLY","FLEX-ONLY","CWW-FLEX","TELE-ONLY","CWW-TELE","FLEX-TELE","Full match")

我将没有YESs 的情况的输出设置为n/a,以便公式更容易理解。将"n/a"公式中的 替换为:

CHOOSE(1+1*(UPPER(B2)="NO")+2*(UPPER(C2)="NO")+4*(UPPER(D2)="NO"),"n/a","n/a","n/a","TELE-ONLY","n/a","FLEX-ONLY","CWW-ONLY","NO-FLEX")

组合公式将正确检测和的任何大小写字符的混合NO,并将YES其他所有内容视为空白:

=CHOOSE(1+1*(UPPER(B2)="YES")+2*(UPPER(C2)="YES")+4*(UPPER(D2)="YES"),CHOOSE(1+1*(UPPER(B2)="NO")+2*(UPPER(C2)="NO")+4*(UPPER(D2)="NO"),"n/a","n/a","n/a","TELE-ONLY","n/a","FLEX-ONLY","CWW-ONLY","NO-FLEX"),"CWW-ONLY","FLEX-ONLY","CWW-FLEX","TELE-ONLY","CWW-TELE","FLEX-TELE","Full match")

解释:

这两个部分中的每一个部分都像一个二进制数字多路复用器一样工作,整个公式就像一个三进制乘法器一样工作。

相关内容