简体   繁体   English

Excel 公式 - 如何有条件地用另一个表中的值填充列

[英]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的ProductionDateExpiryDate之间,并且表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?有没有更简单的方法来写公式?

You can try FILTER() function.你可以试试FILTER() function。

=FILTER($F$4:$F$6,($H$4:$H$6<C4)*($I$4:$I$6>C4)*($G$4:$G$6=B4),"NA")

在此处输入图像描述

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.

相关问题 Excel 列通过宏或公式从另一个 excel 填充 - Excel column fill up from another excel by macro or formula Excel 公式根据另一列中的值填充一列 - Excel formula to fill a column based on value in another column 将值从公式复制到另一列的公式 - A formula to copy the values from a formula to another column 如何填充excel中的列值? - How to fill the column values in excel? Excel - 计算列中不同值数量的公式,不考虑另一列中的指示值 - Excel - formula counting the number of distinct values in column, without taking into account the indicated values from another column Excel 公式 - 如何将 10 列或多列的值堆叠到 1 列中? - Excel formula - How to stack values from 10 or multiple columns into 1 column? 在Excel中使用另一列中的公式 - Using a formula from another column in Excel Excel公式可将一个表中的单元格与另一表中的单元格进行匹配,并返回求和值 - Excel formula to match cells from one table to cells from another table and return summed values 如何根据列分片中的值与另一个表过滤Excel表? - How to filter an Excel table based on values in a column shard with another table? Excel单元格公式,用于计算一个表中的键,如果它们在另一个表中的值是特定条件 - Excel cell formula to count keys from one table, if their values in another table are a specific criteria
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM