简体   繁体   English

在Excel中使用嵌套的IF语句

[英]using Nested IF statement in excel

ID   Height   Phase   Corrected_Height  
1    0        A       0                
2    3.5      A       3.5              
3    1.6      A       NA               
4    11.2     A       11.6               
5    10.1     A       NA                
6    13.2     A       13.1               
7    14.7     A       14.7
8    34.5     A       34.5
9    34.2     A       NA
10   33       A       33
11   40       A       40                 
..
300  237.5    P       237.5             
301  231.7    D       231.7             
302  233.3    D       NA
303  232.1    D       232.1
304  231.7    D       231.7
305  232.1    D       NA
306  234.5    D       234.5 
307  230.1    D       230.1            

555  1.0      D       1.0   

This is a follow-up question to working with Nested IF statement in excel . 这是在excel中使用嵌套IF语句的后续问题。 I have created a column Corrected_height which was calculated with the formula 我创建了一列Corrected_height,该列是使用公式计算的

=IF(AND(B3="A"; A3>=C2);A3;
 IF(AND(B3="A";C2 = "NA");A3;
 IF(AND(B3="D";A3<=C2);A3;
 IF(AND(B3="D";C2 = "NA");B3;
 IF(AND(B3="P");A3;"NA"))))) 

. It works to a certain extent but for example starting ID 8-11, I want ID 10 to be NA because it is in A phase. 它在一定程度上可以工作,但是例如从ID 8-11开始,我希望ID 10为NA,因为它处于A阶段。 And similarly ID 306 too to be NA because it is in D phase. 同样,ID 306也处于NA阶段,因为它处于D阶段。 In the formula it just compares the previous value therefore it does not seem to help. 在公式中,它只是比较先前的值,因此似乎无济于事。 The corrected_height column would need to look like 13.1 14.7 34.5 NA NA 40 .....231.7 NA NA 231.7 NA NA 230.1 corrected_height列的外观应类似于13.1 14.7 34.5 NA NA 40 .....231.7 NA NA 231.7 NA NA 230.1

Lets simplify the IF, since you only want two outputs; 让我们简化IF,因为您只需要两个输出。 NA or the number in column B. NA或B列中的数字。

Then lets use MIN and MAX to check the value to ensure the correct movement: 然后让我们使用MIN和MAX来检查该值以确保正确的运动:

=IF(OR(AND(C3="A";B3<MAX($B$2:B2));AND(C3="D";B3>MIN(INDEX(B:B;MATCH("P";C:C;0)):B2)));"NA";B3)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM