XLOOKUP function for dynamic column header index in a table on Numbers

I have what I think is a fairly straightforward table where I have items in Col A and numbers across Row 1 as headers (these indicate distances so increase to the right).


IN NUMBERS: I am trying to find the number in the table from the intersection of a specific row and column which can be different for different queries. So, one time, I need to select a Col A value from Row 2 and another time I need to select Col A value from Row 5 and in both case need the value at the intersection of Col A and the right Row. The different index is the Column headers where one may be from a Column labeled 12in and another may be from a Column labeled 24in. I can't seem to find a function that allows me to input a Column Heading as a parameter (although I am not great at math so, it could be staring me in the face).


Does this make sense to anyone and might you have any suggestions? I was looking at the XLOOKUP function and possibly embedding another function for the Column Header index but just can't seem to get there ...

Thank you for anything you can suggest.


[Re-Titled by Moderator]

Original Title: NUMBERS function assistance needed

MacBook Pro 14″, macOS 15.6

Posted on Sep 8, 2025 11:26 AM

Reply
Question marked as Top-ranking reply

Posted on Sep 8, 2025 12:56 PM

To find the value at an intersecting point, you need to use MATCH to find the row number and another MATCH to find the column number then use INDEX or OFFSET to get the value at the intersecting point.



Formulas in Table 2:


C2 = MATCH(A2,Table 1::A,0)

D2 = MATCH(B2,Table 1::$1:$1,0)

E2 =OFFSET(Table 1::$A$1,C2-1,D2-1)

fill down to other rows


Note that if you use XMATCH instead of MATCH, you will have to make some adjustments to the formula in E. MATCH includes header rows and columns. XMATCH does not. The two functions give different results.


You can combine C-E into one formula vs using 3 columns to do it. I separated it to illustrate how it worked.


There may be another way to do it with the new "array" functions. If I think of one I'll post it, or maybe someone else will.

9 replies
Question marked as Top-ranking reply

Sep 8, 2025 12:56 PM in response to Iron_Man-2055

To find the value at an intersecting point, you need to use MATCH to find the row number and another MATCH to find the column number then use INDEX or OFFSET to get the value at the intersecting point.



Formulas in Table 2:


C2 = MATCH(A2,Table 1::A,0)

D2 = MATCH(B2,Table 1::$1:$1,0)

E2 =OFFSET(Table 1::$A$1,C2-1,D2-1)

fill down to other rows


Note that if you use XMATCH instead of MATCH, you will have to make some adjustments to the formula in E. MATCH includes header rows and columns. XMATCH does not. The two functions give different results.


You can combine C-E into one formula vs using 3 columns to do it. I separated it to illustrate how it worked.


There may be another way to do it with the new "array" functions. If I think of one I'll post it, or maybe someone else will.

Sep 8, 2025 4:11 PM in response to Iron_Man-2055

Here is one way to do it with the new array functionality. I think the MATCH version is more clear about what it is doing and it will grow with the table without needing any manual adjustment to the formula like this one might. So, really, there was little point in me posting this I guess.


=XLOOKUP(A2,Table 1::A,XLOOKUP(B2,Table 1::$1:$1,Table 1::$2:$8))

Where:

A2 has the value we want to find in column Table 1::A

B2 has the value we want to find in row Table 1::$1:$1

Table 1::$2:$8 is all of Table 1 except for the header row(s)

Sep 8, 2025 6:07 PM in response to Badunit

I'll take a look at this Badunit; thanks of rate alternative.


I did get the MATCH function to work; kind of ... when I change the original search variable, i.e., the name of the item in Col A, the Match function loses it place and doesn't find the correct row in Col A ... does match an order set in the column to search; alphabetical order, something like that?

Sep 9, 2025 7:06 AM in response to Iron_Man-2055

MATCH does a top to bottom search if you are using "exact match", which is what the 0 in the function does. If you have more than one matching item in column A it will return the one closest to the top.


When you say it doesn't find the correct row, what is it "matching" instead?


When you say you "change the name in col A", are you changing the name in Table 1 or Table 2?

Sep 9, 2025 2:03 PM in response to Badunit

It looks like it is skipping ahead to match alphabetically. to an item below the one I am searching for (the items are not in alphabetic order and I am not sure I was using the "0" for an exact match - I'll check on that)


It seems like it might have been looking at a limited number of characters (but that could just be my interpretation of what was going on, of course ...)


I seems that the 2nd XMATCH solution you provided works better and should be fine as once I get the tables built they will have a fixed size that won't change and all searches will be within those boundaries.


Your input is much appreciated!!

Sep 10, 2025 3:34 AM in response to Iron_Man-2055

If you do not use the "exact match" parameter in MATCH or XMATCH, they will try to return a "close match" if they can. But with "exact match", it has to be an exact match (case insensitive) to the entire search term or the result is an error. An extra space character or anything else different betwen the search term and what you are looking for will cause it to not match.

Sep 10, 2025 2:30 PM in response to Badunit

So, at the end of all this - the XLOOKUP function works wonderfully and you are correct that extra spaces will kick your behind because there's no way to know they are there until the formula fails and even then you can't tell where they are without checking every entry. When I built the table it seems (as I have found and removed them) that Numbers sticks spaces randomly at end of lines, sometimes but not always...very confusing not to be able to tell they are there or get some warning that there is a space between your last text and the EOL marker.


Oh well, live and learn as they say! Badunit, I truly appreciate your time on this and all of your suggestions; it all got me where I needed to be! Be well!

Sep 10, 2025 3:38 PM in response to Iron_Man-2055

Iron_Man-2055 wrote:

Numbers sticks spaces randomly at end of lines, sometimes but not always...very confusing not to be able to tell they are there or get some warning that there is a space between your last text and the EOL marker.


It doesn't add anything on its own. If the data was manually typed in, it is as it was typed in. If the data was imported, it imported what it was given. It is not uncommon for imported data to have problems.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

XLOOKUP function for dynamic column header index in a table on Numbers

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.