Solved – Conditional rollups using map and filter functions in Notion Formulas 2.0
📌 The Problem Explained
Section titled “📌 The Problem Explained”In Notion 1.0, users often struggled with “Conditional Rollups.” For example, if you had a Projects database linked to a Tasks database, you could easily roll up the total “Hours” of all tasks. However, if you wanted to sum the hours of only tasks marked as “Completed,” you had to create a “Helper” formula property inside the Tasks database first.
With Notion Formulas 2.0, you no longer need extra helper properties. You can now access related data directly, filter it based on specific criteria, and perform calculations all within a single formula in your parent database.
💡 The Quick Solution
Section titled “💡 The Quick Solution”Use the following formula structure to calculate the sum of a specific property based on a condition. Replace Tasks with your Relation property name, Status with your category, and Hours with your number property.
prop("Tasks").filter(current.prop("Status") == "Done").map(current.prop("Hours")).sum()🛠️ Step-by-Step Breakdown
Section titled “🛠️ Step-by-Step Breakdown”To implement this, follow these steps in your parent database (e.g., Projects):
- Click on Add a property and select Formula.
- Click into the formula editor.
- Use the functions described in the table below to build your logic:
| Function | Purpose | Example Component |
|---|---|---|
| Relation Name | Identifies the database link to pull data from. | prop("Tasks") |
| .filter() | Sets the criteria for which related items to include. | .filter(current.prop("Status") == "Done") |
| current | A keyword representing the specific item being checked. | current.prop("Status") |
| .map() | Picks the specific property (like Price or Hours) from the filtered items. | .map(current.prop("Hours")) |
| .sum() | Adds all the mapped values together. | .sum() |
Full Workflow Example:
Section titled “Full Workflow Example:”If you want to count how many “High Priority” tasks are linked to a project, the formula would be:
prop("Tasks").filter(current.prop("Priority") == "High").length()⚠️ Common Mistakes to Avoid
Section titled “⚠️ Common Mistakes to Avoid”- Forgetting “current”: Inside the
filterandmapfunctions, you must use thecurrentkeyword to reference the properties of the related database. Writingprop("Status")alone will reference the status of the current page, not the related task. - Case Sensitivity: Notion formulas are case-sensitive. If your status is “Done”, searching for “done” (lowercase) will return a result of 0.
- Property Type Mismatch: Ensure the property you are using in
.sum()is a Number property. If you try to sum a Text property, the formula will return an error. Use.length()if you simply want to count the number of items instead of adding values.