Notion Formula 2.0 introduced the ability to work with relation properties directly inside formulas using lambda expressions. Before this update, you could only reference a relation property to count or check existence, but you could not filter, map, or reduce the linked items. This article explains how to write lambda expressions that operate on relation values in Formula 2.0. You will learn the syntax for map, filter, and reduce patterns, and see real examples that aggregate data from a linked database.
Key Takeaways: Using Relation in Formula 2.0 With Lambda
- map() function: Transforms each linked item into a new value, such as extracting a property from every related page.
- filter() function: Returns only linked items that match a condition you define inside the lambda.
- reduce() function: Aggregates all linked items into a single value, like summing a numeric property across related rows.
How Notion Formula 2.0 Handles Relation Properties
In Notion Formula 2.0, a relation property is treated as a list of pages from the linked database. Each item in that list is a page object, and you can access its properties using dot notation inside a lambda expression. A lambda expression is a short anonymous function that you pass to functions like map, filter, and reduce. The lambda defines how each element of the list should be processed.
Before you can use a relation in a formula, you must have a relation property already created between two databases. The formula lives on the source database (the side that contains the relation property). The linked database must contain the properties you want to read, such as a number field called “Amount” or a select field called “Status.”
The general syntax for a lambda in Notion Formula 2.0 uses the pipe operator with the keyword current or a named variable. For example:
prop("Related Items").map(current.prop("Amount"))
This expression takes the relation property named “Related Items,” maps each linked page to its “Amount” property, and returns a list of numbers. You can then pass that list to sum() or other aggregate functions.
Functions That Accept Lambdas
Three list functions accept lambdas in Formula 2.0:
- map() — transforms each element and returns a new list of the same length.
- filter() — returns only elements where the lambda evaluates to true.
- reduce() — combines all elements into a single value using an accumulator.
All three require a lambda as their first argument. The lambda receives each element as a variable (by default named current) and can access properties with the prop() function or dot notation if you assign a variable name.
Writing Lambda Expressions in a Notion Formula 2.0
This section shows how to write a formula that uses a relation property with a lambda. We will use an example where an Invoice database has a relation to a Line Items database. Each line item has a numeric property called “Price.” The goal is to sum all prices from related line items.
- Open the formula editor
In your source database (Invoices), click the + button on a new or existing property column. Select Formula as the property type. The formula editor opens. - Reference the relation property
Typeprop("Line Items")to get the list of linked pages. Replace “Line Items” with the exact name of your relation property. The formula editor will show a list of available properties as you type. - Apply map() to extract the Price
Add.map(current.prop("Price"))after the relation property. This creates a list of Price values from all related line items. The full expression is:prop("Line Items").map(current.prop("Price")) - Use sum() to aggregate
Wrap the entire map expression withsum()to add all prices together. The final formula is:sum(prop("Line Items").map(current.prop("Price"))) - Test the formula
Create at least one invoice and link it to a few line items. The formula should display the total price. If the result is blank, check that the Price property exists on the Line Items database and contains numbers.
Filtering Related Items Before Aggregation
You can combine filter() with map() to work only on a subset of related items. For example, sum only line items where the Status property equals “Paid”:
sum(prop("Line Items").filter(current.prop("Status") == "Paid").map(current.prop("Price")))
The filter() function runs first and returns a list of pages where Status is “Paid.” Then map() extracts the Price from each remaining page, and sum() adds them up.
Using reduce() for Custom Aggregation
The reduce() function gives you full control over how values are combined. It takes a lambda with two arguments: an accumulator and the current element. The lambda must return the new accumulator value. For example, to concatenate all line item names into a single comma-separated string:
prop("Line Items").reduce((acc, current) => acc + ", " + current.prop("Name"), "")
The second argument to reduce() is the initial value of the accumulator (empty string in this case). The lambda takes acc and current, concatenates them with a comma, and returns the result. Note that the first item will have a leading comma because the initial string is empty. You can handle that with a ternary expression inside the lambda.
Common Mistakes and Limitations
Formula Returns Blank or Empty List
If your formula returns blank, first check that the relation property actually has linked pages. A relation with zero items will produce an empty list. Functions like sum() return 0 for an empty list, but other functions like map() may return an empty list that displays as blank in a formula cell. Use the empty() function to test for an empty list: if(empty(prop("Line Items")), 0, sum(...))
Property Name Mismatch
The property names inside the lambda must match exactly the property names in the linked database. Notion property names are case-sensitive. If the property is named “price” in the Line Items database, writing current.prop("Price") will return null. Double-check the spelling and capitalization in the linked database.
Lambda Syntax Errors
Notion Formula 2.0 requires the lambda to be written in a specific way. The arrow function syntax uses => (equals sign followed by greater-than). Do not use spaces inside the arrow: (acc, current) => acc + 1 is correct. Also, when using the default variable name current, you can omit the parentheses: current.prop("Name") is valid.
Performance With Large Relation Lists
Notion Formula 2.0 processes lambdas synchronously in the browser. If a relation property contains hundreds or thousands of linked items, the formula may take several seconds to compute. In extreme cases, the formula may time out and show an error. Keep relation lists under 500 items for reliable performance in formulas.
Notion Formula 2.0 Functions for Relation Lists
| Function | Purpose | Example With Relation |
|---|---|---|
| map() | Transform each linked item into a new value | prop("Items").map(current.prop("Price")) |
| filter() | Keep only items matching a condition | prop("Items").filter(current.prop("Status") == "Active") |
| reduce() | Combine all items into one value | prop("Items").reduce((acc, cur) => acc + cur.prop("Count"), 0) |
| sum() | Add numeric values from a list | sum(prop("Items").map(current.prop("Amount"))) |
| average() | Calculate mean of numeric values | average(prop("Items").map(current.prop("Score"))) |
The table shows the most common functions used with relation properties. Note that sum() and average() work directly on lists returned by map(). You do not need to wrap them inside reduce() for simple aggregation.
You can now write formulas that read, filter, and aggregate data from related databases using lambda expressions. Start by testing the map() and sum() pattern on a small set of linked items. Once you confirm the syntax works, experiment with filter() to narrow down results. For complex custom logic, use reduce() with an accumulator. Remember to keep property names exact and relation lists under 500 items for best performance.