简体   繁体   中英

return multiple different values based on 2 criteria in excel

Hope you can help. I have 2 excel sheets that look like this:

Sheet1:

 ID       trnx       Module
 1        aj08       AA
 2        aj08       AA
 3        aj08       AA
 1        CJ20       ps opex
 1        CJ20       ps capex
 2        cn22       HR

 Sheet 2

 ID       trnx       Module
 1        aj08 
 2        aj08 
 1        ml81
 3        aj08
 2        cn22
 1        cj20
 1        cj20
 3        mm02

The formula im using is

INDEX($G$2:$G$9,SMALL(IF(A2=$F$2:$F$9,ROW($F$2:$F$9)-MIN(ROW($F$2:$F$9))+1,"")&IF(C2=$H$2:$H$9,ROW($H$2:$H$9)-MIN(ROW($H$2:$H$9))+1,""),COUNTIF(A$2:A$2,A2)&COUNTIF(C$2:C$2,C2)))

I need "module" from sheet 2 to be populated based on matching ID and trnx, and if the ID matches but not the trnx, then it must that cell for module to "No Match".

The problem i am experiencing is that sheet 2 is populating the data incorrectly. For Example the second occurrence of ID "1" in sheet 2 is pulling out Module ps opex. it is suppose to be "No Match" since the trnx in sheet 2 is ml81.

please help!!! Thanks in advance:)

This won't address the part I asked in my comment where you have 'duplicate keys' but may help you anyway :

Since your key is really the combination of the Id and the trnx columns, I inserted a concatenated column (I used =CONCATENATE(trnx, "_", id) where those names refer to sheet locations, but you could just as readily concatenate in the other direction as well, or use some other delimiter. It's just to make a single key column (that we can sort on and search more easily.)

In sheet 2 I form the same key column from the values listed there, and then your module column becomes :

 =IF(ISNA(VLOOKUP(I12,$C$10:$D$15,2,0)), "No Match", VLOOKUP(I12,$C$10:$D$15,2,0))

Where in that formula, I12 is the key cell we are looking up in sheet 2, and the absolute reference in the VLOOKUP is the data table in sheet 1.

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