如何修复多个IF条件?

时间:2015-02-02 07:40:34

标签: excel excel-formula

我需要从两列生成输出,如

 A   B  C
 1   1  TP
 1  -1  FN
-1   1  FP
-1  -1  TN

我在C1中使用了以下等式。

=IF(A1=B1,IF(A1=1&B1=1,"TP","TN"),IF(A1=-1&B1=1,"FP","FN"))

和输出就像是,

 A   B  C
 1   1  TN
 1  -1  FN
-1   1  FN
-1  -1  TN

我无法弄清楚上述等式有什么问题。
任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:5)

而不是

A1=1&B1=1

尝试

AND(A1=1,B1=1)

尽管如此,由于您已经确认A和B相同或不相同,因此您只需在辅助IF语句中检查其中一个值。

=IF(A1=B1,IF(A1=1,"TP","TN"),IF(A1=-1,"FP","FN"))

答案 1 :(得分:3)

问题是SCB所说的,即有两个'AND'条件,你需要使用AND()函数,因为否则,你得到&连接符,例如你的第一个公式变成了:

=IF(1=1,IF(1=1&1=1,"TP","TN"),IF(A1=-1&B1=1,"FP","FN"))

哪个变得......

=IF(TRUE,IF(1="11"=1,"TP","TN"),IF(A1=-1&B1=1,"FP","FN"))

则...

=IF(TRUE,IF(FALSE=1,"TP","TN"),IF(A1=-1&B1=1,"FP","FN"))

则...

=IF(TRUE,IF(FALSE,"TP","TN"),IF(A1=-1&B1=1,"FP","FN"))

您应将其更改为:

=IF(A1=B1,IF(AND(A1=1,B1=1)"TP","TN"),IF(AND(A1=-1,B1=1),"FP","FN"))

或更短......

=IF(A1=B1,IF(A1=1,"TP","TN"),IF(A1=-1,"FP","FN"))

虽然我认为做同样事情的有趣方式是:

=IF(A1=B1,"T","F")&IF(B1=1,"P","N")

因为'like'总是给T,如果B1是正数,那么它总是“P”,然后连接两个结果。