Skip to content

Add LET function support for formula evaluation #193

@arcaputo3

Description

@arcaputo3

Problem

The xl formula evaluator doesn't support the LET function, which is commonly used for complex calculations with named variables.

Error

When attempting to use LET formulas, xl fails silently or produces errors:

=LET(
    current_item, E2,
    current_order, A2,
    total_stock, SUMIFS(stock_qtys, stock_items, current_item),
    ...
    result
)

The formula was not evaluated and the output file wasn't created.

What is LET?

LET (introduced in Excel 365/2021) allows defining named variables within a formula:

=LET(
    name1, value1,
    name2, value2,
    calculation_using_names
)

Why This Matters

LET is increasingly used by LLMs when generating complex Excel formulas because:

  1. It improves readability
  2. Avoids repetition (DRY principle)
  3. Can improve performance by computing values once
  4. Makes complex FIFO/allocation logic more maintainable

Example Use Case

From SpreadsheetBench task 2768 (FIFO inventory allocation), the agent attempted:

=LET(
    current_item, E2,
    current_order, A2,
    stock_qtys, Sheet2!$D$2:$D$7,
    stock_items, Sheet2!$C$2:$C$7,
    total_stock, SUMIFS(stock_qtys, stock_items, current_item),
    ... more variables for FIFO logic ...
    result
)

Suggested Implementation

  1. Parse LET as a special function that creates a local scope
  2. Evaluate name-value pairs sequentially
  3. Substitute variable names in the final expression
  4. Return the result of the final expression

Priority

Medium - LET is increasingly common in modern Excel workflows and LLM-generated formulas.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions