Share via

Particular Question on using Lambda, Index, and Match to Look Up in a Table

Anonymous
2023-09-21T14:02:20+00:00

We use lots of sheets that have to look up data in tables based on two variables. I have used the usual look up method, but would like to turn that into an easy-to-use function I can put anywhere. We use this:

=INDEX(A1:H10,MATCH(A15,A1:H1,0),MATCH(A16,A1:A10,0)))

Where:

  • A1:H10 is the table of data with the index values on the top row and left column (X and Y, respectively).
  • A15 is where the X value to be looked up is.
  • A16 is where the Y value to be looked up is.

My first pass at a Lambda function for this is:

=LAMBDA(TL,BL,TR,BR,X,Y,INDEX(TL:BR,MATCH(X,TL:TR,0),MATCH(Y,TL:BL,0)))

Where:

  • TL is the top left cell of the table.
  • BL is the bottom left cell of the table.
  • TR is the top right cell of the table.
  • BR is the bottom right cell of the table.
  • X is the X lookup value.
  • Y is the Y lookup value.

My question is that I would like to streamline this Lambda function so that you only have to input the top left and bottom right cells of the table. The tricky part comes in when you have to put the top row in for the X Match function and the left column in for the Y Match function. The point is, I would like to reduce the inputs to this new function from 6 to 4.

Thanks in advance!

Dave

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2023-09-21T14:54:07+00:00

You switched the row lookup and column indexes: the syntax of INDEX is INDEX(range, row_num, column_num), so MATCH(Y,TL:BL,0) goes before MATCH(X,TL:TR,0).

Define Lookupλ as

=LAMBDA(TL,BR,X,Y, LET(BL, OFFSET(TL, ROW(BR)-ROW(TL)+1, 0), TR, OFFSET(TL, 0, COLUMN(BR)-COLUMN(TL)+1), INDEX(TL:BR, MATCH(Y, TL:BL, 0), MATCH(X, TL:TR, 0))))

Call like this:

=Lookupλ(A1, H10, A15, A16)

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Anonymous
    2023-09-21T15:30:42+00:00

    Fantastic, HansV! Thanks!

    Was this answer helpful?

    0 comments No comments