Combining LET with IF

Wishmaster89

Board Regular
Joined
Jan 10, 2022
Messages
77
Office Version
  1. 2021
  2. 2019
  3. 2016
Platform
  1. Windows
  2. MacOS
Hi All

I'm trying to combine LET with IF but i'm having some trouble. It seems like when i get to the false bit of the IF, the LET statement is out of scope so i can't do a name value 2/name 2 calculation.

In column E, I currently have xlookup and if it doesn't return 0 it performs the original xlookup, which is why i want to use LET to avoid writing out the xlookup twice

This is what i have tried so far , the second function i refer to below is XLOOKUP(A6&C6,$M$2:$M$6&$O$2:$O$6,$Q$2:$Q$6))),XLOOKUP(A6&C6,$M$2:$M$6&$O$2:$O$6,$Q$2:$Q$6)

Excel Formula:
=if(let(a,xlookup(A2&B2,$M$2:$M$6&$N$2:N6,$Q$2:$Q$6))<>0,a,[B]b(2nd function)[/B],

Book2
ABCDEFGHIJKLMNOPQ
1IDStart dateCourse IDCourseGradeIDStart dateCourse IDCourseGrade
2101/03/201933MathsB215/10/202055EnglishF
3215/10/202055EnglishF428/09/202175GeographyA
4307/10/202166ITU303/06/201866ITU
5428/09/202175GeographyA101/03/201933MathsB
6701/03/202112SportsFALSE701/03/202112Sports
Sheet1
Cell Formulas
RangeFormula
E2:E6E2=IFERROR(IF(XLOOKUP(A2&B2,$M$2:$M$6&$N$2:$N$6,$Q$2:$Q$6)<>0,XLOOKUP(A2&B2,$M$2:$M$6&$N$2:$N$6,$Q$2:$Q$6,XLOOKUP(A2&C2,$M$2:$M$6&$O$2:$O$6,$Q$2:$Q$6))),XLOOKUP(A2&C2,$M$2:$M$6&$O$2:$O$6,$Q$2:$Q$6))
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
You need to put the IF inside the LET
Excel Formula:
=LET(a,XLOOKUP(A2&B2,$M$2:$M$6&$N$2:$N$6,$Q$2:$Q$6,0),IF(a<>0,a,XLOOKUP(A2&C2,$M$2:$M$6&$O$2:$O$6,$Q$2:$Q$6,"")))
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
One more question, say i wanted to call the second xlookup "b", is it possible? If i try to put B below i get an error saying too few arguments. I mean its not essential, your original answer does the job, just curious.

Rich (BB code):
=LET(a,XLOOKUP(A2&B2,$M$2:$M$6&$N$2:$N$6,$Q$2:$Q$6,0),B,IF(a<>0,a,XLOOKUP(A2&C2,$M$2:$M$6&$O$2:$O$6,$Q$2:$Q$6,"")))
 
Last edited by a moderator:
Upvote 0
You would need to put the xlookup after the b.
 
Upvote 0
Excel Formula:
=LET(a,XLOOKUP(A2&B2,$M$2:$M$6&$N$2:$N$6,$Q$2:$Q$6,0),IF(a<>0,a,b,XLOOKUP(A2&C2,$M$2:$M$6&$O$2:$O$6,$Q$2:$Q$6,"")))

Sorry i'm not sure where though? Ifi put it where it is now , it messes up the logic of the IF.
 
Upvote 0
Excel Formula:
=LET(a,XLOOKUP(A2&B2,$M$2:$M$6&$N$2:$N$6,$Q$2:$Q$6,0),IF(a<>0,a),b,XLOOKUP(A2&C2,$M$2:$M$6&$O$2:$O$6,$Q$2:$Q$6,"")))

This also doesn't work, i get a LET parameter error.
 
Upvote 0
Hi Try it if your problem is not solved

Excel Formula:
LET(a;XLOOKUP(A2&B2,$M$2:$M$6&$N$2:$N$6,$Q$2:$Q$6);b;XLOOKUP(A2&C2,$M$2:$M$6&$O$2:$O$6,$Q$2:$Q$6);IFERROR(IF(a<>0,a,b)),b))
 
Upvote 0
You need to define b, then add the formula part separately.
Excel Formula:
=LET(a,XLOOKUP(A2&B2,$M$2:$M$6&$N$2:$N$6,$Q$2:$Q$6,0),b,XLOOKUP(A2&C2,$M$2:$M$6&$O$2:$O$6,$Q$2:$Q$6,""),IF(a<>0,a,b))
 
Upvote 0
Solution

Forum statistics

Threads
1,215,482
Messages
6,125,060
Members
449,206
Latest member
Healthydogs

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