Home » excel » Excel Array Lookup Formula

# Excel Array Lookup Formula

Questions:

I have two tables as below. For formulas, assume “ID1” is on cell A1 and one blank row between tables so “ID” is on cell A4.

``````ID1  ID2  ID3  ID4     ID_OF_MAXDATE
a    b    d    #N/A    formula_here

ID     DATE
a      1/1/2015
b      1/2/2015
e      1/3/2015
d      1/4/2015
g      1/5/2015
``````

In the formula, I want the id of the max date if id’s in that row. So in this case, out of a,b,d – the max date is d with 1/4/2015. So the I want the formula to output d.

I have the below so far but the #N/A throws it off. Without the N/A value, the below outputs the max date. However, I want the ID of the max date. And it should ignore N/A’s in the range. Note, all ID’s in table 1 will appear in table 2. But some id columns in table 1 may be N/A.

``````=MAX(IF(A2:D2=A7:A11,B7:B11))
``````

A much bigger and complex formula than expected, but it will take into account that a date can appear more than once in the data set. Be sure and enter with CTRL + SHIFT + ENTER.

``````=IF(SUM(IFERROR(MATCH(A2:D2,\$A\$6:\$A\$10,0),""))>0,LOOKUP(REPT("Z",255),IF(MAX(IF(FREQUENCY(IFERROR(MATCH(TRANSPOSE(A2:D2),\$A\$6:\$A\$10,0),""),ROW(\$B\$6:\$B\$10)-ROW(\$B\$6)+1),\$B\$6:\$B\$10))=IF(FREQUENCY(IFERROR(MATCH(TRANSPOSE(A2:D2),\$A\$6:\$A\$10,0),0),ROW(\$B\$6:\$B\$10)-ROW(\$B\$6)+1),\$B\$6:\$B\$10),\$A\$6:\$A\$10)),"No Match Found")
``````

I also put in some additional error handling. The formula will return “No Match Found” if it is unable to find a match. ``````=MAX(IF(IFERROR(A2:D2,"")=A7:A11,B7:B11))