Two column lookup in table array using INDEX and MATCH

有些话、适合烂在心里 提交于 2019-12-17 03:45:47

问题


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


回答1:


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.




回答2:


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.

      


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



来源:https://stackoverflow.com/questions/33010190/two-column-lookup-in-table-array-using-index-and-match

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!