Notion Formula 2.0 introduced lambda functions, which let you transform each element in an array without writing complex nested formulas. Many users struggle with the syntax and scope of lambda expressions when applying them to database rollups or multi-select properties. This article explains what a lambda function is, how it works with array methods like map(), and provides step-by-step instructions to transform array elements in your Notion databases.
Key Takeaways: Using Lambda in Notion Formula 2.0
- prop(“Items”).map(current, index => current 2): Multiplies each number in the Items array by 2 using a lambda
- prop(“Tags”).filter(current => current.contains(“urgent”)): Keeps only array elements that include the word “urgent”
- prop(“Prices”).reduce(acc, current => acc + current, 0): Sums all numbers in the Prices array using a reducer lambda
Understanding Lambda Functions in Notion Formula 2.0
A lambda function is an inline anonymous function that you pass directly into array methods like map(), filter(), or reduce(). In Notion Formula 2.0, the lambda syntax uses parentheses with parameters, an arrow =>, and an expression. The basic form is (param1, param2) => expression.
When you call prop("ArrayProperty").map(current => expression), the lambda runs once for each element in the array. The variable current holds the current element value. You can also access the index with (current, index) => expression. The lambda must return a single value that becomes part of the new array.
Notion supports three array methods that accept lambdas: map() for transforming each element, filter() for selecting elements that meet a condition, and reduce() for combining all elements into a single value. Each method requires the lambda to return a specific type: the transformed element for map(), a boolean for filter(), and any type for reduce().
Steps to Transform Array Elements with Lambda
- Identify the source property
Open your Notion database and locate the property that contains the array. This can be a multi-select, a rollup that returns an array, or a formula property that outputs an array. Note the exact property name because you will reference it withprop("PropertyName"). - Create or edit a formula property
Add a new Formula property or edit an existing one. Click into the formula editor. The formula must start with the array source followed by a dot and the method name. For example,prop("Numbers").map(current => current + 10)adds 10 to each number. - Write the lambda expression
Inside the parentheses aftermap(), define the lambda. Use a parameter name likecurrentor a single letter such asx. Write the arrow=>and then the transformation expression. For example, to convert each string to uppercase, useprop("Tags").map(current => current.upper()). - Use the index parameter if needed
If your transformation depends on the element position, add a second parameter. The index starts at 0. For instance,prop("Items").map((current, index) => current + index)adds the position number to each value. - Test with a simple filter or reduce
Before applying complex logic, test the lambda with a filter:prop("Numbers").filter(current => current > 5). This returns only numbers greater than 5. Then try reduce:prop("Numbers").reduce((acc, current) => acc + current, 0)sums all numbers. This confirms your lambda syntax works. - Chain multiple array methods
You can combine methods. For example,prop("Numbers").filter(current => current > 5).map(current => current 2)first keeps numbers above 5, then doubles them. Each method returns an array, so the next method receives the filtered array.
Common Mistakes and Limitations
Lambda returns the wrong type
If filter() receives a non-boolean value, it treats it as false. Ensure the lambda expression inside filter() evaluates to true or false. For example, filter(current => current) only works if current is already a boolean. Use explicit comparisons like filter(current => current == true).
Using the wrong parameter name
Parameter names are case-sensitive. If you use Current instead of current in the lambda body, Notion returns an error. Stick to lowercase parameter names to avoid confusion.
Lambda cannot access other row properties
Inside a lambda, you cannot call prop() to fetch another property. The lambda only sees its parameters and global functions like now() or length(). To use other row data, transform the array before the lambda or use a separate formula property.
Array methods return empty arrays on errors
If the source property is not an array, methods like map() return an empty array. Ensure the property type is multi-select, rollup returning an array, or a formula that outputs an array. Use prop("Property").empty() to check for empty arrays before applying lambdas.
Array Method Comparison for Lambda Operations
| Method | Lambda Parameters | Return Value |
|---|---|---|
| map() | (current, index) | New array with transformed elements |
| filter() | (current, index) | New array with elements where lambda returns true |
| reduce() | (accumulator, current, index) | Single accumulated value |
Now you can use lambda functions in Notion Formula 2.0 to transform arrays from multi-select properties, rollups, or formula outputs. Start by applying map() to modify each element, then explore filter() for conditional selection and reduce() for aggregation. An advanced tip: combine filter() and map() in a single formula to both select and transform data without creating intermediate properties.