Intro to formulas

Formulas - hero
In this Article

In a Notion database, you can add a formula property that lets you run all kinds of calculations and functions based on other properties. You can use formulas to manipulate existing data and arrive at many other helpful values 🔮


Notion formulas can perform helpful calculations using your existing database properties, built-ins, and functions.

Let’s look at a few different ways to use formulas. If you’re ready to get started building your own, jump to our instructions on creating a formula below →

Example 1: Project management

In this example, we’ll use three formulas to track the progress of projects.

You can explore and play with the formula setups for this example by duplicating this page to your workspace!

Goal

Property name

Formula

Functions and built-ins used

Set a project’s due date as two weeks after its start date

Due date

dateAdd(Start Date, 2, "week")

dateAdd() adds time to the date. The unit argument can be one of the following: years, quarters, months, weeks, days, hours, or minutes. In this case, we’ll use weeks.

Mark a project as overdue if the due date has passed and its status is not Done.

Mark a project as overdue in bold, red letters if the due date has passed and its status is not Done.

Overdue?

if(and(now() > Due Date, Status != "Done"), "Overdue", "")

if(and(now() > Due Date, Status != "Done"), style("Overdue", "red", "b"), "")

if() returns the first value if the condition is true; otherwise, returns the second value. This allows for a conditional outcome.

and() is a logical operator. This allows to evaluate multiple factors as being true.

now() returns the current date and time. This allows to evaluate where we stand now, compared to the project due date.

> is a comparison operator. This allows to compare the condition of due date being larger than current date.

!= is a comparison operator. This allows to define the condition of status not being equal to Done.

style() adds styles and colors to the text. Valid formatting styles include b (bold), u (underline), i (italics), c (code), or s (strikethrough). Valid colors are gray, brown, orange, yellow, green, blue, purple, pink, and red. Add _background to colors to set background colors. In this case, we’ll apply bold and red.

Show the number of overdue tasks associated with a project

Tasks remaining

length(Tasks.map(current.Status != "Done"))

length() returns the length of the text or list value. This allows for a count of remaining tasks.

map() returns the list populated with the results of calling the expression on every item in the input list. This looks at the tasks database and pulls in all applicable tasks.

!= is a comparison operator. This allows to pull tasks whose current status is not Done.

Example 2: Project brainstorming

In this example, we’ll use two formulas to brainstorm project ideas, calculate a priority score for each of them, and count the number of upvotes each project receives.

You can explore and play with the formula setups for this example by duplicating this page to your workspace! For another setup that uses the RICE framework, check out this template.

Goal

Property name

Formula

Based off of the scores for Reach, Impact, Confidence, and Effort (RICE), calculate a prioritization score

Score (RICE)

Reach * Impact * Confidence / Effort

When someone clicks the upvote button, count them toward the number of total votes and add their name to the database page

Total votes

length(Upvoted by)

(Advanced) Example 3: Task management automation

In this example, we’ll use some formulas in a database automation (another kind of database property) to make it easier to manage projects and tasks as they’re completed by marking a parent task as Done when all its subtasks are Done.

Database automations have triggers and actions that are taken based on those triggers. Formulas allow you to define variables that you can then use in your actions.

You can explore and play with the formula setups for this example by duplicating this page to your workspace!

Goal

How to build it

Functions and built-ins used

Every time a task is set to Done, trigger the automation

Trigger: When status set to Done

-

Define the parent task by finding the first page related to the task that triggered the automation

Action 1: Define Parent task variable

Formula: Trigger page.Parent item.first()

Trigger page references the page in the database the automation was triggered from, and . allows you to access properties associated with that page.

Parent item returns the contents from that property, which in this case is a list of related pages.

Applying the .first() function on the Parent item property returns the first related page from that list.

If the parent task has subtasks, verify whether all its subtasks have a status of Done. If the parent task has no subtasks, return false.

Action 2: Define All subtasks done? variable

Formula: Parent Task.Sub-item ? Parent Task.Sub-item.every(current.Status == "Done") : false

The ternary operator X ? Y : Z is a shorthand conditional expression that means: if the condition X is true, return Y; otherwise, return Z. It's a concise alternative to an if() statement.

.every() checks whether a condition is true for each item in a list. Within this function, you can use the keyword current to refer to the row being evaluated. In this case, the condition current.Status == "Done" checks whether the current page’s status property is set to Done. If so, it will return true; otherwise it will return false.

If all subtasks are Done, set the parent task’s status to Done. If not, retain the existing status of the parent task.

Action 3: Edit Status​ property

Formula: All subtasks done? ? "Done" : Parent Task.Status​

Again, the ternary operator is used here to see if all subtasks are done. If they are, the automation will set the parent task’s status as Done; if not, it will keep the parent task’s status as is.

In Notion, you can use formulas in a few different ways:

To create a formula database property:

  1. Select ••• at the top of a database → PropertiesNew property.

  2. Select Formula.

  3. Give your property a name if you’d like.

  4. Select Edit formula.

Once you’ve created a formula in a database or button, you’ll be able to build and edit that formula in the formula editor, which looks like this:

The field at the top is where you enter and edit your formula. As you write your formula at the top of the editor, the editor will let you know what’s missing, or what the formula expects in order to return a value to you.

The panel on the left side of the edit shows the elements that you can use in the formula — in other words, the properties, built-ins, and functions that are available to you.

The panel on the right side defines formula elements as you hover over them in the left panel. It also gives you examples of how you might use those elements and how they should be structured.

If you open the formula editor from a database row, you'll see a live preview of the result of the formula for that row.

Having trouble with your formula? Learn about common formula errors and how to troubleshoot them in this article →

Formulas can be created using a combination of:

  • Properties.

  • Built-ins, or operators and booleans that are used to set up a specific calculation. Some examples include + (add), false, and or.

  • Functions, or actions that the formula can take to return a certain output. Some examples include replace, sum, and sort.

A full list of the built-ins and functions that are available in formulas is available here →


Give Feedback

Was this resource helpful?


Powered by Fruition