Function Problems

How to Use Nested Thunks in Excel LAMBDA for Combinations

Kushani NimanthikaKushani Nimanthika Nov 10, 2026 869 views

Question details

The user needs to generate every actual combination of m selected objects from n using advanced Excel functions like LAMBDA, SCAN, and REDUCE, rather than just calculating the total combination count.

Using Nested Thunks in Excel LAMBDA to Generate Combinations
Product
Microsoft Excel
Device & OS
not provided
Scenario
Generating comprehensive, multi-dimensional lists of combinations natively within a spreadsheet using dynamic arrays and advanced programming concepts.
Observed behavior
Generating arrays of arrays natively fails because REDUCE cannot handle multiple array outputs directly. Nested thunks are required to wrap arrays into single unevaluated values so REDUCE can process complete rows without error.
Before you start

Ensure you are using a version of Excel that fully supports dynamic array functions (such as LAMBDA, SCAN, and REDUCE). Keep in mind that generating massive arrays can significantly impact spreadsheet performance.

Solution 1

Understand and Create a Basic Thunk

Before generating combinations, you must learn to create a thunk, which stores an array inside an unevaluated function to prevent Excel from expanding it prematurely.

A thunk is essentially an unevaluated LAMBDA function that encapsulates an array. It stores the array as a single value and only returns the evaluated array when explicitly called.

1
Define a basic thunk formula

In your name manager or formula bar, construct a thunk using the syntax: `=LAMBDA(x, LAMBDA(x))`. This tells Excel to hold the value `x` until the inner LAMBDA is called.

2
Store your array

Pass your desired array or combination list into the thunk variable. The array is now stored as a single, actionable object.

3
Unpack the thunk

When you need to retrieve the array inside your REDUCE or SCAN iteration, evaluate the thunk by appending empty parentheses `()` to the thunk's name.

Free Microsoft Office alternative

Try WPS Office for High-Performance Data Processing

Complex array manipulation and massive combination generations can slow down traditional spreadsheets. WPS Office is a lightweight, powerful, and free alternative to Microsoft Office that easily handles heavy data tasks while retaining familiar interfaces.

  1. 1. Download and install WPS Office: Visit the official WPS Office website to download the free suite and follow the straightforward installation prompts.
  2. 2. Open your spreadsheet: Launch WPS Spreadsheet and open your existing .xlsx files without worrying about formatting loss.
  3. 3. Utilize advanced functions: Take advantage of WPS Spreadsheet's high-speed calculation engine to process your complex mathematical data seamlessly.
Fully compatible with Microsoft Excel formats (.xlsx, .xls, .csv).Lightweight installation ensures faster processing for heavy data tasks.Supports comprehensive modern array functions for complex data analysis.Free to use with a highly intuitive, tabbed interface for seamless migration.
microsoft office alternative - wps office

Frequently Asked Questions

What exactly is a 'thunk' in Excel?

A thunk is an advanced programming concept adapted for Excel. It is an unevaluated LAMBDA function that encapsulates an array, storing it as a single callable object. It only 'unpacks' or evaluates the array when it is explicitly called with empty parentheses '()'.

Why use nested thunks instead of standard dynamic arrays?

Excel's calculation engine does not natively support 'arrays of arrays'. If a function like REDUCE tries to return multiple separate arrays, Excel throws a value error. Nested thunks bypass this by tricking Excel into treating the wrapped arrays as single values.

Can I generate combination lists without using the COMBIN function?

Yes. While COMBIN(n,m) only calculates the total numerical count of possible combinations, using advanced combinations of LAMBDA, SCAN, REDUCE, and nested thunks allows you to generate and display the actual itemized lists of every combination.

What are the limits of generating combinations in a spreadsheet?

The output is heavily restricted by spreadsheet capacity constraints (a maximum of 1,048,576 rows) and computational memory. In practical applications using nested thunks, the upper limit for returning actual combinations is roughly 200,000 before the application freezes or crashes.