简体   繁体   English

根据2个条件在列中查找值

[英]Find value in column, based on 2 criteria

I have a file with 3 columns. 我有一个包含3列的文件。 Column A contains 300,000 rows, with about 200 separate IDs, all duplicated at least 1,000 times. A列包含300,000行,带有大约200个独立的ID,所有ID至少重复了1000次。 Column B contains the date for each of the rows. B列包含每一行的日期。 Column C contains the values that I need to extract. C列包含我需要提取的值。

Each of the 200 IDs in Col A can have multiple values (eg ID 1234 might have dates 1/1/2001, 1/3/2001, 1/2/2015, etc). Col A中的200个ID中的每个ID可以具有多个值(例如ID 1234的日期可能为1/1 / 2001、1 / 3 / 2001、1 / 2/2015等)。 Similarly, each date on Col B will have multiple IDs (eg 1/2/15 might have IDs of 1234, 1874, 1930, 6043, etc). 同样,列B上的每个日期将具有多个ID(例如1/2/15可能具有1234、1874、1930、6043等)。

In a nutshell, I need to check the values in Col A and Col B to find the relevant ID in Col A and the maximum value in Col B, and return the value in the relevant cell in Col C. 简而言之,我需要检查Col A和Col B中的值以找到Col A中的相关ID和Col B中的最大值,然后在Col C中的相关单元格中返回值。

I've looked at Index/Match examples, but they don't seem to be suitable. 我看过索引/匹配示例,但它们似乎不合适。 Is there any suggestions on a macro I could run, that would accomplish what is needed. 在我可以运行的宏上是否有任何建议,可以完成所需的内容。

Use this array formula: 使用此数组公式:

=INDEX($C$1:$C$300000,MATCH(1,IF(($A$1:$A$300000="1234")*($B$1:$B$300000=MAX(IF($A$1:$A$300000="1234",$B$1:$B$300000))),1,0),0))

Being an array formula it must be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode. 作为数组公式,退出编辑模式时必须使用Ctrl-Shift-Enter而不是Enter进行确认。

Change the "1234" to a reference cell with the appropriate ID. "1234"更改为具有适当ID的参考单元格。

You can accomplish this using array formulas. 您可以使用数组公式来完成此操作。 To start, you can retrieve the maximum date in column B when column A is 1234 using the below formula. 首先,您可以使用以下公式在A列为1234时检索B列中的最大日期。 Keep in mind that you have to use Ctrl-Shift-Enter when you finish typing an array formula. 请记住,在完成数组公式的键入后,必须使用Ctrl-Shift-Enter。

{=MAX(IF($A$2:$A$24=1234,$B$2:$B$24))}

Note that you will need to change the ranges to include all of your data, rather than my test data on rows 2-24. 请注意,您将需要更改范围以包括所有数据,而不是2-24行中的测试数据。

Now that you have a formula to retrieve the max date, you can put that inside an index/match and, again using Ctrl-Shift-Enter, use the below array formula to retrieve the value in column C for a row matching 1234 and the maximum date. 现在您有了一个可以检索最大日期的公式,可以将其放入索引/匹配项中,然后再次使用Ctrl-Shift-Enter,使用下面的数组公式来检索C列中与1234和最长日期。

{=INDEX($C$2:$C$24,MATCH(1234&MAX(IF($A$2:$A$24=1234,$B$2:$B$24)),$A$2:$A$24&$B$2:$B$24,0))}

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

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