Forum Discussion
Does a LET variable get computed even if it's only referenced inside IFNA's fallback argument?
Yes, your second restructuring is necessary if you want to avoid computing the heavy lookup unnecessarily.
Here is why:
While functions like IFNA and IF support short-circuiting (evaluating fallback arguments only when needed), Excel’s LET function evaluates variable bindings at the time they are declared in the top-level scope.
In your first formula, because expensive Match is assigned as a variable binding inside LET, Excel computes the INDEX/XMATCH calculation immediately during assignment—before IFNA(x, expensive Match) is even executed.
In your second formula:
=LET(
matchRow, XMATCH(1, (A1=Sheet2!$A$1:$A$1000)*(B1=Sheet2!$B$1:$B$1000)),
x, INDEX(Sheet2!$C$1:$C$1000, matchRow),
IF(ISNA(x), INDEX(Sheet3!$C$1:$C$500, XMATCH(A1&B1, Sheet3!$A$1:$A$500&Sheet3!$B$1:$B$500)), x)
)
By removing expensiveMatch from the LET definition and placing the lookup inside IF(ISNA(x), ...), Excel defers calculation and only executes the second lookup when x actually results in #N/A.
If you are working with large string lookups or external reference tables (such as processing large custom https://japangeneratorname.com/ or multi-criteria array matches), the second method will eliminate unnecessary recalculation overhead.