简体   繁体   中英

Find value in column, based on 2 criteria

I have a file with 3 columns. Column A contains 300,000 rows, with about 200 separate IDs, all duplicated at least 1,000 times. Column B contains the date for each of the rows. Column C contains the values that I need to extract.

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). Similarly, each date on Col B will have multiple IDs (eg 1/2/15 might have IDs of 1234, 1874, 1930, 6043, etc).

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.

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.

Change the "1234" to a reference cell with the appropriate 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. Keep in mind that you have to use Ctrl-Shift-Enter when you finish typing an array formula.

{=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.

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.

{=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))}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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