Excel LAMBDA function tutorial with Leila Gharani

Download the LAMBDA Practice Workbook

Follow along with the examples from the video and build your first reusable LAMBDA functions step by step. No VBA needed.

What Is the LAMBDA Function in Excel?

Have you ever struggled with long, complicated formulas in Excel? The LAMBDA function can change that.

It lets you create custom functions and reuse them across your workbook, without writing a single line of code.

Think of it like creating your very own Excel formula. You give it a name, define how it works, and then use it anytime you need.

It’s that simple!

LAMBDA Syntax: Parameters and Calculation

LAMBDA has two main parts:

  1. Inputs (Parameters): These are placeholders for the values you want to calculate.
  2. Formula: The calculation or logic Excel will perform.

For example, to find percentage change:

New Value / Old Value - 1

You can turn this into a reusable LAMBDA function:

=LAMBDA(old, new, new/old - 1)

Now you can reuse this function anytime.

For more details about calculating percentage change in Excel check out this post.

How to Create a LAMBDA Function in Excel

In this example, we’re comparing Budget Sales to Actual Sales for four regions. We want to calculate the percentage change.

Budget and actual sales for four regions with an empty % Change column

Step 1: Start with the Formula

Write the formula for percentage change in cell D2:

=C2 / B2 - 1

In this case:

  • C2 = Actual sales (New Value)
  • B2 = Budgeted sales (Old Value)

After entering the formula, format the cell as a percentage:

  • Right-click the cell, choose Format Cells, and select Percentage.
Percentage change formula =C2/B2-1 in cell D2 returning 3%

Step 2: Turn It into a LAMBDA Function

Replace the cell references with placeholders. You can name these placeholders anything you like (e.g., budget and actual).

The placeholders act as inputs for the function:

=LAMBDA(budget, actual, actual / budget - 1)

Note: If you enter this LAMBDA in a cell now, Excel shows a #CALC! error. That is expected. The function has no input values yet. You add them in the next step.

LAMBDA formula without inputs returning a #CALC! error in cell D2

Step 3: Test Your LAMBDA

To test the LAMBDA function, use this special syntax:

=LAMBDA(budget, actual, actual/budget-1)(B2, C2)
  • The first part defines the placeholders (budget and actual) and the formula.
  • The second part, in parentheses, provides the actual input values from your table (e.g., B2 for Budget Sales and C2 for Actual Sales).
LAMBDA tested in the cell with (B2,C2) at the end returning 3%

Note: The extra parentheses at the end are key. They pass the input values to the LAMBDA (B2 for Budget Sales and C2 for Actual Sales).

It allows you to test the formula directly on the worksheet to ensure it works correctly before saving it. Think of it as a way to preview your custom function!

Step 4: Save It in Name Manager

  1. Copy your LAMBDA formula, but leave out the testing parameters at the end (e.g., the (B2, C2) part).
  2. Open the Name Manager:
    • Use the shortcut Control + F3 (or go to the Formulas tab and select Name Manager).
    • Click New, give your function a name (e.g., PercentageChange),
    • Leave the scope set to “Workbook”.
    • Paste the formula into the “Refers To” field.
    • Add a short Comment that explains each parameter, for example budget = old value, actual = new value. It reminds you and your colleagues what the function needs.
    • Press OK to save it.
New Name dialog saving the LAMBDA as PercentageChange in Name Manager

Now that the LAMBDA formula has a name, you can use it like any other Excel function in your workbook.

Naming Rules for LAMBDA Functions

When naming your custom LAMBDA function in Excel, follow these guidelines:

  1. Length: Names must be between 1 and 255 characters.
  2. Starting Character: The name must start with a letter (A-Z, a-z) or an underscore (_).
  3. No Spaces: Use letters, numbers, periods and underscores only, for example Sales_Tax.
  4. Avoid Cell References: Names like B1, C5, or F10 are not allowed.
  5. Avoid Built-In Function Names: Do not use names like IF, VLOOKUP, or MATCH.

Note: LAMBDA names are not case-sensitive. Excel treats XelPlus and xelplus as the same name, so pick one clear name for each function.

Step 5: Use Your Custom Function

In the % Change column, type:

=PercentageChange(B2, C2)
Custom PercentageChange function used in cell D2 like a built-in function

Practical Example: Sort a List by the Sum of Another Column

Here’s how to create a function to sort departments by total salary in descending order.

Your dataset looks like this:

Employee data with department, name, position and salary columns

We don’t show the salary totals, only the sorted lists of departments and positions. The final output shows:

  • A list of departments, sorted by total salary.
  • A list of positions, sorted by total salary.
Departments and positions sorted by total salary in descending order

We’ll use LAMBDA to create a custom function. It will generate these lists automatically, without needing to manually aggregate or sort them.

Step 1: Write and Test the Formula

Select an empty cell and enter this formula:

=SORTBY(UNIQUE(A4:A19), SUMIFS(D4:D19, A4:A19, UNIQUE(A4:A19)), -1)
  • UNIQUE: Creates a list of unique departments or positions.
  • SUMIFS: Adds up salaries for each unique value.
  • SORTBY: Sorts the list by total salaries in descending order (-1).

This formula generates a sorted list of departments.

SORTBY, UNIQUE and SUMIFS formula sorting departments by total salary

Step 2: Turn the Formula into a LAMBDA

1. Turn the test formula into a LAMBDA by replacing the ranges with placeholders. We’ll use:

  • Items for A4:A19 (the Department column)
  • Salary for D4:D19

2. Replace the ranges with the parameter names to create the LAMBDA formula:

=LAMBDA(Items, Salary, SORTBY(UNIQUE(Items), SUMIFS(Salary, Items, UNIQUE(Items)), -1))

3. Test the function by entering the formula with the parameter values:

=LAMBDA(Items,Salary, SORTBY(UNIQUE(Items), SUMIFS(Salary, Items, UNIQUE(Items)), -1))(A4:A19, D4:D19)
LAMBDA with Items and Salary parameters tested on the department column

Step 3: Save It as SortBySum

  1. Copy the LAMBDA formula from Step 2, without the test ranges in brackets at the end.
  2. Open the Name Manager with Ctrl + F3.
  3. Create a new name, such as SortBySum, and paste the formula into the “Refers To” field.
Edit Name dialog saving the LAMBDA as SortBySum

Step 4: Use SortBySum on Any Column

Now, you can use your custom function in any cell. For example to get the sorted positions enter this formula in cell G4:

=SortBySum(C4:C19, D4:D19)

This will return the sorted list of positions based on their salary totals in descending order.

SortBySum function returning positions sorted by total salary in cell G4

Going Further: Recursive LAMBDAs

A LAMBDA can also call itself. This is called a recursive LAMBDA, and it lets a formula loop, much like For Next or Do While in VBA.

The video shows one in action: a MegaReplace function that runs through a list of before and after values and fixes every mistake in a cell, for example Office 365 to Microsoft 365. See how a recursive LAMBDA works for the full build.

Longer LAMBDAs get cramped in the Name Manager box. The Advanced Formula Environment gives you a proper editor to write and manage them.

Which Excel Versions Have LAMBDA?

LAMBDA works in Excel for Microsoft 365 (Windows and Mac), Excel 2024 and Excel for the web.

It is not available in Excel 2021 or older versions.

Download the LAMBDA Practice Workbook

Download the LAMBDA Practice Workbook

Get the workbook and turn your own formulas into custom functions.

Frequently Asked Questions

What does the LAMBDA function do in Excel?

LAMBDA turns a formula into your own custom function. You save it with a name in Name Manager and then use it like a built-in function anywhere in the workbook, without VBA or macros.

Why does my LAMBDA return a #CALC! error?

A LAMBDA entered in a cell without any inputs returns #CALC!. Add the inputs in brackets at the end, for example =LAMBDA(x, x*2)(5), or save the LAMBDA in Name Manager and call it by its name.

How do I save a LAMBDA as a custom function?

Go to Formulas > Name Manager or press Ctrl+F3, click New and type a name. Paste the LAMBDA without the test inputs into the Refers to box and click OK. You can now call the function by that name.

Can I use my LAMBDA in another workbook?

A LAMBDA is saved as a name in one workbook. To use it elsewhere, copy a worksheet that uses the function into the other workbook, which brings the name along, or add the same name in that workbook with Name Manager.

How many parameters can a LAMBDA have?

A LAMBDA can have up to 253 parameters. The calculation is always the last argument. If you pass the wrong number of inputs, Excel returns a #VALUE! error.

Which Excel versions support LAMBDA?

LAMBDA works in Excel for Microsoft 365 on Windows and Mac, Excel 2024 and Excel for the web. Excel 2021 and older versions do not have it.

Leila Gharani

Founder of XelPlus and ten-time Microsoft MVP. Leila helps over 500,000 professionals master Excel, Power BI, and data automation through practical, real-world training.