hermes

Write a reusable LAMBDA function

Writes a reusable Excel LAMBDA or named function for a repeated calculation, with parameters, LET for readability, examples and edge cases. Use when the same long formula is copied across a workbook.

context

You are an Excel specialist who writes custom functions with LAMBDA so that a business rule lives in one place instead of in two hundred copied formulas. A good named function reads like a sentence where it is used (=NETDAYS(Start, End)), names its intermediate steps with LET, handles bad inputs on purpose, and works on a whole column at once when the inputs are ranges.

task

Write a named LAMBDA function for this calculation.

calculation

example inputs

  1. Define the contract in two lines: the parameters (name, type, required or optional) and the return value (single value or array, type, and what it returns for invalid input).
  2. If the calculation is ambiguous (units, rounding, what counts as blank, inclusive or exclusive bounds), ask one short question listing the points, and stop. If it is clear enough, continue and list your assumptions.
  3. Write the function:
  • Name: short, uppercase, verb or noun that says what it returns, not clashing with a built-in function.
  • Parameters in the order a user would think of them; optional parameters last, handled with ISOMITTED and a sensible default.
  • A LET inside the LAMBDA that names each step, ending with a final named result.
  • Input checks where a wrong input would give a plausible but wrong number (for example text instead of a date): return a clear error such as #VALUE! or a short message, instead of hiding it with IFERROR around the whole function.
  • If the inputs may be ranges, make the result spill correctly: use element-wise operations, or MAP and BYROW when a step is not element-wise (AND and OR are not; use * and + on conditions instead).
  1. Show how to test it inline before naming it: the same LAMBDA followed by arguments in brackets in a cell.
  2. Check it against the example inputs (or examples you construct if none were given) and show each call with its result. Include at least one edge case.
constraints
  • LAMBDA, ISOMITTED, MAP and BYROW need Microsoft 365, Excel for the web or Excel 2024. LET alone is available from Excel 2021. Say this, and give a plain-formula fallback for older versions when it is short.
  • Google Sheets has LAMBDA and Named functions (Data > Named functions) with a similar model but no ISOMITTED; if the user may need Sheets, say what changes.
  • Avoid recursion unless the task needs it; if you use it, say what stops it and that very deep recursion can fail.
  • Keep the definition paste-ready: no line comments inside it. Explain pieces in the text below instead.
  • Use comma separators and note once that some locales use semicolons.
output format

Function

The name, then the full =LAMBDA(...) definition in a code block. Long definitions may use line breaks for readability.

Add it to the workbook

Steps: Formulas > Name Manager > New, the name, the definition in "Refers to", and a comment describing the parameters (it appears as the tooltip). One line on the Advanced Formula Environment add-in for managing many functions.

Parameters

Table: Parameter | Type | Required | Default | Meaning.

Examples

Table: Call | Result | Why.

Edge cases

Table: Input | Returns | Intended?

Compatibility

Versions that support it, the fallback formula, and the Google Sheets notes.

examples
example

Calculation: percentage change from old to new, blank when old is zero or either value is blank.

=LAMBDA(old, new,
  LET(
    valid, (old <> 0) * (old <> "") * (new <> ""),
    change, (new - old) / ABS(old),
    IF(valid, change, "")
  )
)

Named PCTCHANGE. =PCTCHANGE(B2:B100, C2:C100) spills one result per row because every step is element-wise.

1 required value still a placeholder; the assistant will ask for it.

details

kind
Prompt: a task you run by name to get one finished thing back
domain
Data analysis
category
Spreadsheets
level
Expert
made for
Data analyst, Financial analyst, Business analyst
risk
read-only
version
v1.0.0 · incubating
reviewed
2026-10-03
works in
Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Antigravity, OpenCode, Windsurf, Zed, Continue, AGENTS.md, ChatGPT, claude.ai

Edit on GitHubReport a problem

use in

Hodios CLI
npx @hermes-hq/hodios install write-lambda-function --target claude-code

This entry is in the full catalog, not the curated set the skills installer and plugins carry, so install it with the Hodios CLI.

pairs well with

All of Spreadsheets
PromptSpreadsheets

Write a spreadsheet formula

Builds an Excel or Google Sheets formula from a plain-language goal and the sheet layout, explains how it works and flags edge cases. Use when you know the result you want but not the formula.

write-spreadsheet-formula
PromptSpreadsheets

Debug a spreadsheet formula

Finds why an Excel or Google Sheets formula errors or returns wrong values and gives the corrected formula. Use for #N/A, #VALUE!, wrong totals, or results that break when copied down.

debug-spreadsheet-formula
PersonaSpreadsheets

Spreadsheet expert

Spreadsheet expert who builds clean, auditable Excel and Google Sheets workbooks, prefers simple formulas over clever ones and explains each step. Use as a standing spreadsheet helper.

spreadsheet-expert
PromptSpreadsheets

Extract tables from a PDF

Extracts tables from PDF or scanned text into clean CSV, Markdown or JSON, keeps values exactly as printed, flags likely OCR errors and validates totals against the source. Use before analysis.

extract-tables-from-pdf
PromptSpreadsheets

Run a what-if analysis

Builds a scenario and sensitivity analysis for a decision (best, base and worst cases, a tornado chart and breakevens) as a spreadsheet layout with exact formulas. Use before committing to a plan.

run-what-if-analysis
PromptSpreadsheets

Audit a spreadsheet model

Audits a spreadsheet model for hard-coded values, broken ranges, inconsistent formulas, circularity, unit mistakes and missing checks, ranked by impact. Use before relying on someone else's sheet.

audit-spreadsheet-model