XLOOKUP two-way, use "if not found" for both ways

aapdonBK

New Member
Joined
Dec 2, 2024
Messages
4
Office Version
  1. 365
Platform
  1. MacOS
Hi,
I'm trying to look up a department A14 (in columns) and account A13 (in rows). Sometimes, the department won't exist. Other times the account may not exist.

This formula works if the account does not exist and returns a zero. Great!
=+XLOOKUP($A14,$A$2:$A$8,XLOOKUP($B14,$B$1:$D$1,$B$2:$D$8),0)
But, if the department does not exist, I get an "#N/A".

So, I tried adding another "if not found" in bold here:
=+XLOOKUP($A15,$A$2:$A$8,XLOOKUP($B15,$B$1:$D$1,$B$2:$D$8,0),0)
But, I got "#VALUE!" instead of a zero.

I cannot figure out how to have both the column and the row XLOOKUP in this nested formula use "if not found" criteria. The data changes every quarter, and I don't want to have to add fake data or mess with the formula each time. I need it to return 0 if either or both are not found.

Any ideas on using XLOOKUP here?
xlookup.jpg


Thanks!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
You are going to need to use IFERROR. If you don't need to return a different result based on which one is erroring out then just use that and don't worry about the XLookup version.
Excel Formula:
=IFERROR(XLOOKUP($A14,$A$2:$A$8,XLOOKUP($B14,$B$1:$D$1,$B$2:$D$8)),0)
 
Upvote 0
Solution
The nested (inner) XLOOKUP function is returning a single column of values, which is used as the return_array argument of the outer XLOOKUP function. If you want to utilize the [if_not_found] argument of the inner XLOOKUP function, it will also need to be a single column of values that is the same height as the lookup_array. In this particular example, since you only want to return a 0 when no match is found, you can simply specify an empty range somewhere off to the right of your data table, e.g. $E$2:$E$8 or $XFD$2:$XFD$8.

Excel Formula:
=XLOOKUP(A13,$A$2:$A$8,XLOOKUP(B13,$B$1:$D$1,$B$2:$D$8,$XFD$2:$XFD$8),0)
 
Upvote 0
Welcome to the MrExcel board!

Is there a particular need to use XLOOKUP at all?

24 12 03.xlsm
ABCD
1AccountMarketingITAdmin
21000405060
3110010001080
41200455565
5130010031383
61400506070
7150010061686
81600556575
9
10
11
12
131200Marketing45
141650IT0
151600Overhead0
161600Overhead0
Sheet2 (2)
Cell Formulas
RangeFormula
C13:C16C13=IFNA(INDEX(B$2:D$8,XMATCH(A13,A$2:A$8),XMATCH(B13,B$1:D$1)),0)
 
Last edited:
Upvote 0
The nested (inner) XLOOKUP function is returning a single column of values, which is used as the return_array argument of the outer XLOOKUP function. If you want to utilize the [if_not_found] argument of the inner XLOOKUP function, it will also need to be a single column of values that is the same height as the lookup_array. In this particular example, since you only want to return a 0 when no match is found, you can simply specify an empty range somewhere off to the right of your data table, e.g. $E$2:$E$8 or $XFD$2:$XFD$8.

Excel Formula:
=XLOOKUP(A13,$A$2:$A$8,XLOOKUP(B13,$B$1:$D$1,$B$2:$D$8,$XFD$2:$XFD$8),0)
Thanks for the explaining "single column of values that is the same height".
 
Upvote 0
You are going to need to use IFERROR. If you don't need to return a different result based on which one is erroring out then just use that and don't worry about the XLookup version.
Excel Formula:
=IFERROR(XLOOKUP($A14,$A$2:$A$8,XLOOKUP($B14,$B$1:$D$1,$B$2:$D$8)),0)
Thanks for this easy solution.
 
Upvote 0
Welcome to the MrExcel board!

Is there a particular need to use XLOOKUP at all?

24 12 03.xlsm
ABCD
1AccountMarketingITAdmin
21000405060
3110010001080
41200455565
5130010031383
61400506070
7150010061686
81600556575
9
10
11
12
131200Marketing45
141650IT0
151600Overhead0
161600Overhead0
Sheet2 (2)
Cell Formulas
RangeFormula
C13:C16C13=IFNA(INDEX(B$2:D$8,XMATCH(A13,A$2:A$8),XMATCH(B13,B$1:D$1)),0)
Thanks for this working alternative. I'm just learning more about XLOOKUP.
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,266
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top