[英]Excel formula - How to conditionally fill a column with values from another table
I have 2 tables here:我这里有 2 张桌子:
I want to fill up the Code
column in Table 1 by referring to Table 2. The condition for the value is that the Start date must be in between the ProductionDate
and ExpiryDate
of Table 2, and the Type in Table 1 must match the Type in Table 2, else return NA.我想参照表2填写表1中的Code
一栏,取值条件是Start date必须在表2的ProductionDate
和ExpiryDate
之间,并且表1中的Type必须与Type in相匹配表 2,否则返回 NA。 I have come up with the formula for cell D4
我想出了单元格D4
的公式
=IFS(AND(C4>=$H$4,C4<=$I$4,B4=$G$4),$F$4,AND(C4>=$H$5,C4<=$I$5,B4=$G$5),$F$5,AND(C4>=$H$6,C4<=$I$6,B4=$G$6),$F$6)
Is there a simpler way to write the formula?有没有更简单的方法来写公式?
I have found another way to write the formula:我找到了另一种写公式的方法:
By naming the range F4:F6 as code
, G4:G6 as type
, H4:H6 as prod_date
, and I4:I6 as exp_date
, we can use the IFERROR() and MATCH() function as below.通过将范围 F4:F6 命名为code
, G4:G6 命名为type
, H4:H6 命名为prod_date
,并将 I4:I6 命名为exp_date
,我们可以使用 IFERROR() 和 MATCH() function 如下。
=IFERROR(MATCH(1,(B4=type) * (C4>=prod_date) * (C4<=exp_date),0),"NA") =IFERROR(MATCH(1,(B4=type) * (C4>=prod_date) * (C4<=exp_date),0),"NA")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.