Google Sheets LAMBDA Function: How to Use It
In this article
The LAMBDA function in Google Sheets lets you create your own custom function using a formula, without writing Apps Script. You define the function's parameters, write the calculation, and then call it by name just like SUM or AVERAGE. This is useful for repeated calculations, complex logic, or sharing a formula with others who don't need to see the inner workings. To use LAMBDA, you need a Google account and access to Google Sheets; no additional add-ons or permissions are required.
What You'll Need
- A Google account with access to Google Sheets (free or Workspace).
- A spreadsheet where you want to use the custom function.
- Basic familiarity with spreadsheet formulas and cell references.
- Optional: Named ranges if you want to make your LAMBDA easier to read.
Step-by-Step
- Open your Google Sheet and decide where you want to use the custom function. You can enter the LAMBDA directly in a cell or define it as a named function for reuse across the sheet.
- Write the LAMBDA formula. The syntax is
=LAMBDA(parameter1, parameter2, ..., calculation). For example, to create a function that doubles a number, you would write=LAMBDA(x, x*2)(5)to immediately call it with 5, which returns 10. Alternatively, you can define it as a named function (next step) and then call it by name. - To create a reusable named function, go to Data > Named functions > Add new function. In the sidebar, enter a name for your function (e.g.,
DOUBLE), then in the "Function definition" field, enter the LAMBDA formula without calling it, like=LAMBDA(x, x*2). You can also add argument placeholders and descriptions. Click "Done" to save. - Use your named function in any cell by typing
=DOUBLE(5)or referencing a cell like=DOUBLE(A1). The function will calculate using the LAMBDA logic you defined. - Test and adjust. If you need to change the logic, go back to Data > Named functions, select your function, and edit the definition. Changes apply wherever the function is used.
- Share or copy. Named functions are saved with the spreadsheet. If you copy the sheet, the named function comes along. To use it in another sheet, you can copy the cell containing the named function or recreate it there.
Note: Menu labels may vary slightly by version, device, or region. The steps above are for the desktop web version of Google Sheets; the mobile app has limited support for creating named functions.
Common Mistakes
- Forgetting to call the LAMBDA. A LAMBDA by itself returns a function, not a value. You must either call it immediately with arguments (e.g.,
=LAMBDA(x, x*2)(5)) or assign it to a named function and then call that. - Using the wrong number of arguments. The number of parameters in the LAMBDA must match the number of arguments you pass when calling it. If you define
LAMBDA(x, y, x+y), you must call it with two values. - Circular references. If your LAMBDA refers to the cell it's in, you'll get a circular dependency error. Ensure the calculation uses only the parameters or other cells.
- Name conflicts. Named functions cannot have the same name as built-in functions or existing named ranges. Choose a unique name.
- Not accounting for empty cells. If your LAMBDA expects a number but receives an empty cell, it may return an error. Use IF or ISBLANK to handle such cases.
Tips
- Use descriptive parameter names (e.g.,
price,quantity) to make your LAMBDA easier to understand. - You can nest LAMBDAs, but keep it simple to avoid confusion.
- Combine LAMBDA with other functions like MAP or BYROW to apply it to ranges. For example,
=MAP(A1:A10, LAMBDA(x, x*2))doubles each value in the range. - Document your named functions with a description in the Named functions sidebar so others know what they do.
- Test your LAMBDA with sample data before applying it to large ranges.
Troubleshooting
If your LAMBDA doesn't work as expected, try these steps:
- Check for typos in the function name, parameter names, and formula syntax. Ensure parentheses and commas are correct.
- Verify argument count. The number of arguments passed must equal the number of parameters defined.
- Look for #NAME? errors if you're calling a named function that doesn't exist or is misspelled. Go to Data > Named functions to confirm the name.
- Check for #VALUE! errors if the calculation uses incompatible data types (e.g., text instead of numbers). Use IFERROR or data validation to handle.
- If the function returns unexpected results, test the LAMBDA with simple inputs to isolate the issue. Break down the calculation into smaller parts.
- If you can't find the Named functions menu, ensure you're using the desktop web version; the mobile app may not support creating named functions.
- If changes to a named function don't apply, try refreshing the sheet or re-entering the formula.
Frequently Asked Questions
Can I use LAMBDA without creating a named function?
Yes, you can use LAMBDA directly in a cell by calling it immediately, like =LAMBDA(x, x*2)(5). This is useful for one-off calculations.
What's the difference between LAMBDA and a regular formula?
A regular formula is evaluated immediately. A LAMBDA defines a reusable function that can be called multiple times with different inputs, making it easier to maintain complex logic.
Can I use LAMBDA with array formulas?
Yes, LAMBDA can be combined with functions like MAP, BYROW, and BYCOL to apply a custom function across a range. For example, =MAP(A1:A10, LAMBDA(x, x*2)).
Do named functions work in other spreadsheets?
Named functions are saved with the spreadsheet. If you copy the sheet, they come along. To use them in a different spreadsheet, you'll need to recreate them or copy the cell containing the function.
Is LAMBDA available in the Google Sheets mobile app?
The mobile app supports using existing named functions, but creating or editing named functions is best done on the desktop web version.
Can I use LAMBDA to create recursive functions?
Google Sheets LAMBDA does not support recursion directly. You would need to use Apps Script for recursive logic.