简体   繁体   English

在Excel中索引和匹配多个条件

[英]Index and Match Multiple Criteria in Excel

I have two tables of data with the same columns. 我有两个具有相同列的数据表。 The first is populated with experimental data: 第一个填充有实验数据:

`Treatment  Species TimeofDay   Temp    Light   X
     M        B       AM         25      25     2
     M        B       PM         26      50     3
     M        B       PM         27      150    4
     M        C       AM         25      25     5
     M        C       AM         26      150    6
     M        C       PM         27      500    7
     M        C       PM         28      800    9
     A        B       AM         25       25    2
     A        B       PM         26       50    3
     A        B       PM         27       150   4
     A        C       AM         25       25    5
     A        C       AM         26      150    6
     A        C       PM         27      500    7
     A        C       PM         28      800    9

In the second table I want to fill in the "X" column with values from the first table so that in the given row A) all of the categorical values match exactly those from table one AND B) Temp and Light values are closest (but won't be exact) to matching values in table 1. 在第二张表中,我想用第一张表中的值填写“ X”列,以便在给定的行A)中所有分类值与表一中的所有分类值完全匹配并与B)Temp和Light值最接近(但并非完全正确)以匹配表1中的值。

For example, if in Table 2 I have: 例如,如果在表2中,我有:

Treatment  Species  TimeofDay  Temp  Light  X
    M         B        PM       30    200

I would want the function to give me 4 in the X column. 我希望函数在X列中给我4。 I am familiar with indexing a value in one column given a match in another and with finding a closest matching value in a column, but I am having trouble putting all these criteria together: 我熟悉在给定另一列匹配项的一列中索引值并在列中找到最接近的匹配值,但是我很难将所有这些条件放在一起:

=INDEX(Table1!F$2:F$20,
MATCH(Table2!A$2,Table1!A$2:A$20,0))
MATCH(Table2!B$2,Table1!B$2:B$20,0))
MATCH(Table2!C$2,Table1!C$2:C$20,0))
MATCH(MIN(ABS(Table1!D$2:D$20-Table2!D$2)),ABS(Table1!D$2:D$20-Table2!D$2), 0))
MATCH(MIN(ABS(Table1!E$2:E$20-Table2!E$2)),ABS(Table1!E$2:E$20-Table2!E$2),0))

Thank you in advance for your help. 预先感谢您的帮助。

This formula is working, put in F2: 此公式有效,放在F2中:

=INDEX(Table1!F:F,MATCH(MIN(IF(A2=Table1!A:A,IF(B2 = Table1!B:B,IF(C2 = Table1!C:C,ABS((Table1!D:D+Table1!E:E)-(D2+E2)))))),IF(A2=Table1!A:A,IF(B2 = Table1!B:B,IF(C2 = Table1!C:C,ABS((Table1!D:D+Table1!E:E)-(D2+E2))))),0))

This is an array formula and must be confirmed with Ctrl-Shift-Enter when exiting edit mode. 这是一个数组公式,退出编辑模式时必须使用Ctrl-Shift-Enter确认。 Then copy down. 然后抄下来。

As to your other comment the priority if the difference is the same will be the first in order. 至于您的其他评论,如果差异相同,则优先顺序为第一。

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

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