如何修复多个 IF 条件?
How to fix multiple IF condition?
我需要从两列生成输出,例如,
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
我无法弄清楚上面的等式有什么问题。
任何帮助将不胜感激。
而不是
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"))
问题是 SCB 所说的,即有两个“与”条件,您需要使用 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",然后连接两个结果。
我需要从两列生成输出,例如,
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
我无法弄清楚上面的等式有什么问题。
任何帮助将不胜感激。
而不是
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"))
问题是 SCB 所说的,即有两个“与”条件,您需要使用 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",然后连接两个结果。