If your data is sorted as you have it in the example, ie. by first column ascending, then second column ascending. Then you can use a combination of OFFSET()
, INDEX()
and MATCH()
.
=OFFSET(INDEX(second_column,MATCH(lookup_a,first_column,0)),entry_row-1,0)
This first acquires the cell address with INDEX(..., MATCH())
of the first cell matching your lookup value, then the OFFSET()
function knocks that down by how many rows you want within that group. Of course this entirely depends on the sorting being as described.
If you wanted the kth-smallest entry in an unsorted second column (but still grouped on the first column), then you could use:
=SMALL(OFFSET(second_column,MATCH(lookup_a,first_column,0)-1,0,MATCH(lookup_a,first_column,1)-MATCH(lookup_a,first_column,0)+1,1),entry_row)
This has the advantage of returning #N/A
if you move out of bounds on your selection. Surrounding it with IFERROR(...., "")
.
Alternatively, using the first method for unsorted second column data and just checking the offset to see if it retains the lookup value, you can use:
=IF(OFFSET(OFFSET(INDEX(second_column,MATCH(lookup_a,first_column,0)),entry_row-1,0),0,-1)=lookup_a,OFFSET(INDEX(second_column,MATCH(lookup_a,first_column,0)),entry_row-1,0),"")