The logic in that Lambda formula is trying to check whether `n` itself equals `#N/A`, but `n` is a date, it will never be an error. The real condition needs to test the *result* of the first XLOOKUP, not the input. This is a classic misunderstanding of how error handling works in spreadsheet formulas, and it highlights a broader truth: recursive thinking in spreadsheets is powerful, but it demands a different mental model than the linear cell references most users rely on.
What this user is trying to do, find the closest previous date with data when exact matches don't exist, is a legitimate and common need. Their instinct to use recursion is reasonable, but the implementation reveals a gap between the conceptual goal and the syntax available in Excel or Google Sheets. The `IF` function cannot directly evaluate an error state the way they attempted; you need `IFERROR` or `ISNA` to catch the error *after* the lookup runs. Even then, a recursive approach here is fragile because each decrement of `n` by 1 risks infinite loops or performance issues if the table is large or the date range is wide.
The smarter path, as the comment section noted, is to avoid recursion entirely. A single `XLOOKUP` with the `-1` match mode parameter does exactly what they need: it finds the closest previous date when an exact match is missing. That is the elegant, intuitive solution that the Lambda formula overcomplicated. The lesson is that recursion should be a tool of last resort in spreadsheets, not the first impulse. Before writing a custom recursive function, ask whether built-in lookup parameters already solve the problem.
For users who feel constrained by traditional spreadsheet logic, this example is instructive. The technology is evolving to handle fuzzy and approximate matches more gracefully than ever. The frustration of a broken formula often stems not from the tool's limits, but from assuming the tool works the same way a programming language does. Embrace the declarative nature of spreadsheets: tell the tool *what* you want (closest previous match), not *how* to loop backward through rows. That shift in thinking is what separates a workable formula from a recursive dead end.