How to Troubleshoot Thunks with SCAN and LAMBDA in Excel
Question details
The user needs to correctly implement and troubleshoot Excel SCAN formulas that utilize thunks to pass multiple state variables through repeated LAMBDA iterations.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Writing complex dynamic array formulas where multiple variables must be maintained and updated across each loop of an iterative function.
- Observed behavior
- Errors occur when carrying multiple states through iterations, often triggered by invalid LET variable names, overly complex array constructions, or returning intermediate states when only the final state is desired.
Ensure you are using a version of Microsoft Excel that supports Dynamic Arrays and the LAMBDA, SCAN, and REDUCE functions, such as Microsoft 365.
Use Standard Callable LAMBDAs for Thunks
Wrap the state in a callable LAMBDA and evaluate it inside the SCAN function to safely pass variables between iterations.
A thunk delays calculation by encapsulating values in a parameter-less LAMBDA. This allows SCAN to carry complex arrays or multiple states without breaking.
Create a LAMBDA function to encapsulate your multiple state variables so they can be passed as a single object.
Within your SCAN iteration, call the previous thunk (e.g., previousLambda()) to unpack the current states.
Perform your mathematical or logical operations on the unpacked variables to determine the new values.
When defining variables with LET, never use names that match cell references (like x1 or A1). Use distinct names like _x1 or varA.
Re-wrap the newly calculated state variables into a new callable LAMBDA and return it for the next iteration.

Implement a CHOOSE-Based LAMBDA Storage
Use a combination of LAMBDA and CHOOSE to store and retrieve multiple variables by an index number during each iteration.
Master Advanced Data Analysis with WPS Spreadsheet
WPS Office offers a powerful, free Spreadsheet application that natively supports advanced data analysis, dynamic arrays, and complex formulas. You can seamlessly open, edit, and troubleshoot your complex workbooks.
- 1. Download and Install: Get WPS Office Free from the official website and install it on your computer.
- 2. Open your Workbook: Launch WPS Spreadsheet and open the Excel file containing your complex LAMBDA and SCAN iterations.
- 3. Edit the Formula: Select the cell with your thunk logic and use the Formula Bar to easily edit, format, and audit the code.
- 4. Debug Variables: Use the built-in error checking tools to identify reference conflicts or invalid variable names within your LET statements.

Frequently Asked Questions
What is a thunk in Excel formulas?
A thunk is a parameter-less LAMBDA function used to encapsulate and delay the evaluation of a value or expression. This allows you to pass complex arrays or multiple state variables through iterative functions like SCAN and REDUCE without triggering immediate calculation errors.
Why do my LET variable names cause #NAME? errors?
If you use variable names in the LET function that match standard Excel cell references (such as A1, X1, or FD1), the calculation engine interprets them as conflicting cell references rather than custom variables. Always use distinct prefixes, like _x or var1.
Should I use SCAN or REDUCE for my LAMBDA iterations?
Use SCAN if you need to output an array showing the intermediate results of every step in the iteration. If you only care about the final accumulated state at the very end of the loop, use the REDUCE function to save memory and simplify your output.
How do I extract values from a CHOOSE-based LAMBDA?
By passing an index number to the CHOOSE-based LAMBDA (for example, myLambda(2)), the internal CHOOSE function evaluates the index and returns the corresponding variable stored at that specific position.




