Two column lookup in table array using INDEX and M

2019-01-04 03:37发布

I would like excel to display the value from table array which has two matching cells com_cd and div_cd using INDEX and MATCH.

I have tried the following formula but it did not work.

=INDEX(K9:K53,MATCH(K3,I9:I53,0),MATCH(K4,J9:J53,0)) 

Here is a screenshot of the excel sheet with the desired result given according to com_cd and div_cd

div

2条回答
做个烂人
2楼-- · 2019-01-04 04:34

Your column_num parameter on the INDEX function cannot sinply provide a secondary row criteria. You need a way to ensure a two column match on the row_num parameter and leave the column_num either blank or as 1 (there is only only column in K9:K53).

The standard formula for K5 should be,

=index(K9:K53, aggregate(15, 6, row(1:45)/((i9:i53=k3)*(j9:j53=k4)), 1))

... or,

=index(K9:K53, min(index(row(1:45)+((i9:i53<>k3)+(j9:j53<>k4))*1e99, , )))

The cell range K9:K53 has a total of 45 rows. The position within K9:K53 will be within ROW(1:45). The first formula forces any non-matching row into an #DIV/0! error state and the AGGREGATE¹ function uses option 6 to ignore errors while retrieving the smallest valid entry with the SMALL sub-function (e.g. 15). The second formula performs the same action by adding 1E+99 (a 1 followed by 99 zeroes) to any non-matching row and taking the smallest matching row with the MIN function.

      AGGREGATE two column match


¹ The AGGREGATE function was introduced with Excel 2010. It is not available in earlier versions.

查看更多
神经病院院长
3楼-- · 2019-01-04 04:38

Try an array formula (CTRL + SHIFT + ENTER) instead of Enter.

=INDEX(K9:K53,MATCH(K3&K4,I9:I53&J9:J53,0),1)

Not tested but should work.

Will edit later explaining our formula and reason why your formula doesn't work.

查看更多
登录 后发表回答