Notion Formula 2.0 introduced lambda functions, which let you define reusable logic inside a formula property. Without lambdas, you must repeat calculations or write long nested expressions. This article explains what lambdas are, how to define them with the let() and arrow functions, and how to use them to simplify complex formulas. You will learn the syntax, practical examples, and common pitfalls to avoid.
Key Takeaways: Defining and Using Lambdas in Notion Formula 2.0
- let() function + arrow =>: Defines a named lambda that can be called multiple times inside a formula.
- Arrow function syntax (params => expression): Creates an inline anonymous lambda without a name.
- Recursive lambdas with let() and this: Allows a lambda to call itself for iterative operations like factorial or string reversal.
What Are Lambdas in Notion Formula 2.0?
A lambda is a function you define inside a formula property. Unlike built-in functions (like formatDate or sum), lambdas are user-defined. They accept parameters and return a single value. Lambdas are first-class values, meaning you can pass them as arguments to other functions or store them in variables using let().
The main benefit of lambdas is code reuse. If you need to apply the same transformation to multiple fields in a formula, you write the logic once inside a lambda and call it repeatedly. Lambdas also enable recursion, which is impossible with plain expressions.
To use lambdas, your workspace must have Notion Formula 2.0 enabled. This is the default for all new workspaces created after 2023. If you have an older workspace, check the formula editor for a toggle labeled “Use new formula engine” at the top right.
How to Define a Lambda with let() and Arrow Functions
There are two ways to define a lambda in Notion Formula 2.0: using a named variable inside let() or creating an anonymous arrow function directly in an expression.
Method 1: Named Lambda Using let()
The let() function binds one or more variables to values. The value can be a lambda. The syntax is:
let( lambdaName, (param1, param2) => expression, resultExpression )
The first argument is the variable name (no quotes). The second argument is the lambda definition. The third argument is the expression where you can call the lambda. You can define multiple lambdas by adding more pairs.
Example: Calculate the area of a rectangle and double it.
let( area, (w, h) => w h, area(5, 3) 2 )
This returns 30. The lambda area multiplies width and height. The result expression calls it with 5 and 3, then multiplies by 2.
Method 2: Anonymous Arrow Function
An anonymous lambda is an arrow function without a name. It is useful when you need to pass a function to a higher-order function like map() or filter(). The syntax is:
(params) => expression
Example: Double each number in a list.
[1, 2, 3].map((x) => x 2)
This returns [2, 4, 6]. The lambda is defined inline inside map().
Practical Examples of Lambdas in Formulas
The following examples show lambdas solving real problems in Notion databases.
Example 1: Normalize Text Fields
Suppose a database has a Title property and a Description property. You want to trim whitespace, convert to lowercase, and remove punctuation from both. Without a lambda, you would repeat the chain for each field.
let(
clean, (text) => replaceAll(lower(trim(text)), "[^a-z0-9 ]", ""),
clean(prop("Title")) + " " + clean(prop("Description"))
)
The lambda clean applies all three transformations. You call it on both properties, making the formula shorter and easier to edit.
Example 2: Recursive Factorial
Recursion requires a named lambda that can reference itself. Use let() with a variable that refers to the lambda via this.
let( fact, (n) => if(n <= 1, 1, n this(n - 1)), fact(5) )
This returns 120. The lambda calls itself using this, which refers to the lambda being defined. Note that this only works inside a let() variable binding.
Example 3: Filter and Transform a Rollup
A rollup property returns a list of values from related database rows. Use filter() and map() with lambdas to process the list.
prop("Related Tasks").filter((task) => task.Status == "Done").map((task) => task.Name)
This returns the names of all completed tasks. The first lambda filters, the second maps.
Common Mistakes and Limitations of Lambdas
Lambda Does Not Have Access to prop() or let() Bindings
A lambda only sees its parameters and global built-in functions. It cannot directly call prop("Name") or access variables defined in an outer let(). To use a property value, pass it as an argument when calling the lambda.
Incorrect:
let(
greet, () => "Hello " + prop("Name"),
greet()
)
Correct:
let(
greet, (name) => "Hello " + name,
greet(prop("Name"))
)
Recursive Lambda Exceeds Stack Limit
Notion limits recursion depth to about 1000 calls. If your lambda recurses too deeply, the formula returns an error. For iterative operations over large lists, use reduce() or map() instead of recursion.
Lambda Cannot Be Used Outside the let() Scope
A lambda defined inside let() is only available in the result expression of that same let(). You cannot reference it in another part of the formula outside the let() block. Define the lambda again in each block where it is needed.
Notion Formula 2.0 Lambda Syntax vs Traditional Expression
| Item | Lambda | Traditional Expression |
|---|---|---|
| Reusability | Define once, call many times | Must repeat logic each time |
| Recursion support | Yes, via this keyword |
Not possible |
| Inline definition | Anonymous arrow function | Not applicable |
| Readability for complex logic | High, logic is named | Low, long nested chains |
| Performance | Same as traditional | Same as lambda |
Lambdas are the recommended approach for any formula that repeats the same transformation or requires recursion. Traditional expressions are suitable for simple one-off calculations.
You can now define and call lambdas in Notion Formula 2.0 to reduce repetition and enable recursion. Start by converting one repetitive formula in your database to use a named lambda with let(). For advanced use, try combining map() and filter() with anonymous lambdas to process rollups. Remember to pass property values as arguments, not access them inside the lambda.