Detailed guide on how to use notion formulas for 2024.

Explore Notion Formulas with this detailed guide. Master the art of calculations, automate tasks, and enhance your workspace efficiency.

Dec 18, 2023
Detailed guide on how to use notion formulas for 2024.
Notion isn't just your average productivity tool; it's perfect for individuals and big shots managing a whole bunch of people in their business.
If you’re a Notion Enthusiast, you might heard about Notion Formulas. If not, No worries, this article will explain you everything about the Notion Formulas. They’re like the secret sauce that can take your Notion Workspace to a whole new level.
Even seasoned users sometimes find them a bit intimidating. So we will be diving into notion Formulas and give you a crash course on all the concepts in Notion Formulas.
Lets get started

What are Notion Formulas?

Notion formulas act like excel formulas, boosting the functionality of your Notion databases. You write and apply them in Formula properties within your Notion databases.

Creating a Formula Property

Follow these steps to add a formula to your Notion database:
  1. Click on the ••• menu in your database.
  1. Choose Properties and click on + Add a property.
  1. Opt for Formula from the options.
  1. Click Edit and start writing your formula.

How to write a Formula

If you've had any experience with Excell, Notion's formulas are very similar familiar! You get to pick functions (tasks to perform) and inputs (data to work with). The formula then crunches the numbers, and the output (the result) shows up in the new formula property for each row in your database.
Here's a quick example in this formula: prop("Created By").name()
  • The function is name()
  • name() takes the name from the “Created by” Property column of the database.
  • The output will be the name representing the created by property.

Formula Editor

When you click within the content area of a formula property, Notion opens up its formula editor for you.
This editor is divided into four main sections:
  1. Editor Field: This is where you write your formulas. You can format them with line breaks and indentation for better readability. Inline comments are supported.
  1. Live Preview: Right beside the editor, you get a live preview of the current value returned by your formula. If there are any errors, this preview transforms into a list of those errors.
  1. Scrollable List: You have a scrollable list displaying all available properties, built-ins, functions, and variables. Just click on one, and it'll be added to your formula right where your cursor is.
  1. Context Window: This window gives you a description of the currently selected or hovered formula component. It's your go-to for understanding what each part does. Also, you'll find a syntax reference and a few examples to guide you.
 
notion image
With the latest updates to Notion's formula editor, you can now enjoy the convenience of new lines, indentation, and comments, making it a breeze to craft intricate formulas without having to leave Notion.
  • To add new lines, simply use Shift + Enter.
  • For indentation, press the Tab key.
  • If you want to add comments, use /*This is a comment */

Formula Datatypes

Notion Formulas have the power to handle and return various data types. While many property types are supported, keep in mind that their data type will be converted as and when needed.
Let's break it down by types:

1. String

The String data type is designed to store and convey textual content. By default, Strings can accommodate nearly any character.
Example: "Hello world”

2. Numbers

The Number data type is designed to hold and represent numerical values. Numbers can be used with mathematical operators like addition (+) and division (/) to execute various mathematical operations and calculations.
Examples: 1, -2.5

3. Booleans

Boolean values indicate truth states, existing as either true or false. In Notion, these Boolean values are visually represented through checkboxes:
  • True is symbolized by a checked box.
  • False is symbolized by an unchecked box.

4. Date

Notion formulas have the capability to handle and generate date objects, a distinct data type.
These date objects stand apart from strings since they can be manipulated using specialized date functions like dateAdd and dateSubtract.
Notion's date object comprises three essential parts:
  • Start date
  • End date (optional)
  • Time zone
Within a Notion formula, the following functions output date objects:
  • start()
  • end()
  • now()
  • fromTimestamp()
  • dateAdd()
  • dateSubtract()

5. List (a.k.a Arrays)

In Notion, a list data type is responsible for storing a collection of items that you can access and manipulate using various functions. In many programming languages, these are commonly referred to as arrays, and they significantly enhance the capabilities of Notion formulas.
Some of List functions are at(), filter(), map(), and so on to manipulate the lists.

6. People

People data type is responsible to retrieve data using name() or email() for People types which displays as people’s names along with their photos.

7. Pages

Pages in Notion are like relations, symbolizing various connections. To access page properties, you can use a dot (.) notation. When displayed, it appears as a rich page link adorned with the page's distinctive icon.

Properties in Formulas

Formulas in Notion are versatile, accommodating various property types. If a particular type isn't directly supported, the data is automatically converted into another data type, typically text.
Property Types
Examples
Formula Type
Title
prop("Title") prop("Title").length()
Text
Text
prop("Text") prop("Text").length()
Text
Select
prop("Priority") == "High"
Text
Multi-Select
prop("Tags").length() prop("Tags").includes("Finance")
Text
Checkbox
prop("Checkbox") not prop("Checkbox")
Boolean
Email, URL, Phone Number
!empty(prop("Phone")) !empty(prop("Email")) link("Call", "tel:" + prop("Phone"))
Text
Unique ID
prop("Task ID").split("-").first() ← Prefix prop("Task ID").split("-").last() ← ID
Text
Created By, Edited By
prop("Created By").name() prop("Created By").email()
Person
Person
prop("Person") prop("Person").at(0).name() prop("Person").map(current.email())
Person
Date, Created Time, Last Edited Time
prop("Due Date") > now() dateBetween(prop("Birthday"), now(), "days")
Date
Number
prop("Number") / 2 pi() * prop("Radius") ^ 2
Number
Relation
prop("Tasks").length() prop("Tasks").filter(current.prop("Status") !== "Done")
Page
Rollup
prop("Purchases").length() prop("Average cost") * 12
Number, date, or list of any type. Depends on rollup configuration.

Built-ins

Built-ins refer to particular symbols and values inherently integrated into the language to facilitate and signify calculations.
Built-in
Example
Math operators: +, -, *, %
2 * pi() "hello" + "world"
Boolean values: true, false
true false
Comparison operators: ==, >, >=, <, <=
123 == 123 = true "Notion" == "Motion" = false
Logical operators: and, or, not
and: true and false true && false and(true, false) or: true or false true || false or(true, false) not: not true !true
Ternary operator: ? :
X ? Y : Z is equivalent to if(X, Y, Z)

Functions

Notion formulas are built using the functions listed below.
Name
Description
Example
if
Returns the first value if the condition is true; otherwise, returns the second value.
if(true, 1, 2) = 1 if(false, 1, 2) = 2  prop("Checked") == true ? "Complete" : "Incomplete"
ifs
Returns the value that corresponds to the first true condition. This can be used as an alternative to multiple nested if() statements.
ifs(true, 1, true, 2, 3) = 1 ifs(false, 1, false, 2, 3) = 3
empty
Returns true if the value is empty. 0, “”, and [] are considered empty.
empty(0) = true empty([]) = true
length
Returns the length of the text or list value.
length("hello") = 5 length([1, 2, 3]) = 3
substring
Returns the substring of the text from the start index (inclusive) to the end index (optional and exclusive).
substring("Notion", 0, 3) = "Not" substring("Notion", 3) = "ion"
contains
Returns true if the search string is present in the value.
contains("Notion", "ot") = true
test
Returns true if the value matches the regular expression and false otherwise.
test("Notion", "Not") = true test("Notion", "\\d") = false
match
Returns all matches of the regular expression as a list.
match("Notion Notion", "Not") = ["Not", "Not"] match("Notion 123 Notion 456", "\\d+") = ["123", "456"]
replace
Replaces the first match of the regular expression with the replacement value.
replace("Notion Notion", "N", "M") = "Motion Notion"
replaceAll
Replaces all matches of the regular expression with the replacement value.
replaceAll("Notion Notion", "N", "M") = "Motion Motion" replaceAll("Notion 123", "\\d", "") = "Notion"
lower
Converts the text to lowercase.
lower("NOTION") = "notion"
upper
Converts the text to uppercase.
upper("notion") = "NOTION"
repeat
Repeats the text a given number of times.
repeat("0", 4) = "0000" repeat("~=", 10) = "~=~=~=~=~=~=~=~=~=~="
link
Creates a hyperlink from the label text and the URL.
link("Bullet", "https://bullet.so") = "Bullet"
style
Adds styles and colors to the text. Valid formatting styles:  "b" (bold), "u" (underline), "i" (italics), "c" (code), or "s" (strikethrough). Valid colors: "gray", "brown", "orange", "yellow", "green", "blue", "purple", "pink", and "red". Add "_background" to colors to set background colors.
style("Notion", "b", "u") = "Notion" style("Notion", "blue", "gray_background")
unstyle
Removes formatting styles from the text. If no styles are specified, all styles are removed.
unstyle("Text") unstyle("Text", "b")
format
Returns the value formatted as text.
format(1234) = "1234" format(now()) = "December 14, 2023 19:40"
add
Returns the sum of two numbers.
add(5, 10) = 15 5 + 10 = 15
subtract
Returns the difference of two numbers.
subtract(5, 10) = -5 5 - 10 = -5
multiply
Returns the product of two numbers.
multiply(5, 10) = 50 5 * 10 = 50
mod
Returns the first number modulo the second number.
mod(5, 10) = 5 5 % 10 = 5
pow
Returns the result of a base number raised to an exponent power.
pow(5, 10) = 9765625 5 ^ 10 = 9765625
divide
Returns the quotient of two numbers.
divide(5, 10) = 0.5 5 / 10 = 0.5
min
Returns the smallest number of the arguments.
min(1, 2, 3) = 1 min([1, 2, 3]) = 1
max
Returns the largest number of the arguments.
max(1, 2, 3) = 3 max([1, 2, 3]) = 3
sum
Returns the sum of its arguments.
sum(1, 2, 3) = 6 sum([1, 2, 3], 4, 5) = 15
abs
Returns the absolute value of the number.
abs(10) = 10 abs(-10) = 10
round
Returns the value of a number rounded to the nearest integer.
round(0.4) = 0 round(-0.6) = -1
ceil
Returns the smallest integer greater than or equal to the number.
ceil(0.4) = 1 ceil(-0.6) = 0
floor
Returns the largest integer less than or equal to the number.
floor(0.4) = 0 floor(-0.6) = -1
sqrt
Returns the positive square root of the number.
sqrt(4) = 2 sqrt(7) = 2.6457513110645907
cbrt
Returns the cube root of the number.
cbrt(9) = 2.080083823051904 cbrt(64) = 4
exp
Returns e^x, where x is the argument, and e is Euler's number (2.718…), the base of the natural logarithm.
exp(1) = 2.718281828459045 exp(-1) = 0.36787944117144233
ln
Returns the natural logarithm of the number.
ln(2.718281828459045) = 1 ln(10) = 2.302585092994046
log10
Returns the base 10 logarithm of the number.
log10(10) = 1 log10(100000) = 5
log2
Returns the base 2 logarithm of the number.
log2(4) = 2 log2(1024) = 10
sign
Returns 1 if the number is positive, -1 if it is negative, and 0 if it is zero.
sign(-10) = -1 sign(10) = 1
pi
Returns the ratio of a circle's circumference to its diameter.
pi() = 3.141592653589793
e
Returns the base of the natural logarithm.
e() = 2.718281828459045
toNumber
Parses a number from text.
toNumber("2") = 2 toNumber(now()) = 1693443300000 toNumber(true) = 1
now
Returns the current date and time.
now() = @December 14, 2023 19:44 PM
minute
Returns the minute of the date (0-59).
minute(parseDate("2023-12-14T19:45Z")) = 45
hour
Returns the hour of the date (0-23).
hour(parseDate("2023-12-14T19:45Z")) = 19
day
Returns the day of the week of the date, between 1 (Monday) and 7 (Sunday).
day(parseDate("2023-07-10T17:35Z")) = 1
date
Returns the day of the month from the date (1-31).
date(parseDate("2023-12-14T19:45Z")) = 14
week
Returns the ISO week of the year of the date (1-53).
week(parseDate("2023-12-14")) = 3
month
Returns the month of the date (1-12).
month(parseDate("2023-12-14T19:47Z")) = 12
year
Returns the year of the date.
year(now()) = 2023
dateAdd
Adds time to the date. The unit argument can be one of: "years", "quarters", "months", "weeks", "days", "hours", or "minutes".
dateAdd(now(), 1, "days") = @December 15, 2023 19:49 PM dateAdd(now(), 2, "months") = @January 14, 2024 19:50PM dateAdd(now(), 3, "years") = @December 14, 2026 19:50 PM
dateSubtract
Subtracts time from the date. The unit argument can be one of: "years", "quarters", "months", "weeks", "days", "hours", or "minutes".
dateSubtract(now(), 1, "days") = @December 13, 2023 19:51 PM dateSubtract(now(), 2, "months") = @September 14, 2023 19:52 PM dateSubtract(now(), 3, "years") = @December 14, 2020 19:52 PM
dateBetween
Returns the difference between two dates. The unit argument can be one of: "years", "quarters", "months", "weeks", "days", "hours", or "minutes".
dateBetween(now(), parseDate("2022-09-07"), "days") = 463 dateBetween(parseDate("2035-01-01"), now(), "years") = 11
dateRange
Returns a date range constructed from the start and end dates.
dateRange(prop("Start Date"), prop("End Date")) = @December 14, 2022 → December 14, 2023
dateStart
Returns the start of the date range.
dateStart(prop("Date Range")) = @December 14, 2022 dateBetween(dateStart(prop("Date Range")), dateEnd(prop("Date Range")), "days") = -365
dateEnd
Returns the end of the date range.
dateEnd(prop("Date range")) = @December 14, 2023 dateBetween(dateEnd(prop("Date Range")), dateStart(prop("Date Range")), "days") = 365
timestamp
Returns the current Unix timestamp, representing the number of milliseconds that have elapsed since January 1, 1970.
timestamp(now()) = 1702564260000
fromTimestamp
Returns the date from the given Unix timestamp. The timestamp represents the number of milliseconds that have elapsed since January 1, 1970. Note: the returned date will not retain the seconds & milliseconds.
fromTimestamp(1702564260000) = @December 14, 2023 20:01 PM
formatDate
Formats the date using a custom format string. The format string can contain the following text to represent parts of the date: "YYYY" for year, "MM" for month, "DD" for day, "HH" for hour, "mm" for minute.
formatDate(now(), "MMMM D, Y") = "December 14, 2023" formatDate(now(), "MM/DD/YYYY") = "12/14/2023" formatDate(now(), "HH:mm A") = "20:04 PM"
parseDate
Returns the date parsed according to the ISO 8601 standard.
parseDate("2022-01-01") = @January 1, 2022 parseDate("2023-12-14T00:00Z") = @December 14, 2023 5:30 AM
name
Returns the name of a person.
name(prop("Created By")) prop("Pioneers").map(name(current)).join(", ") = "Grace Hopper, Ada Lovelace"
email
Returns the email address of a person.
email(prop("Created By")) prop("People").map(email(current)).join(", ")
at
Returns the value at the specified index in a list.
at([1, 2, 3], 1) = 2
first
Returns the first item in the list.
first([1, 2, 3]) = 1
last
Returns the last item in the list.
last([1, 2, 3]) = 3
slice
Returns the items of the list from the provided start index (inclusive) to the end index (optional and exclusive).
slice([1, 2, 3], 1, 2) = [2] slice(["a", "b", "c"], 1) = ["b", "c"]
concat
Returns the concatenation of multiple lists.
concat([1, 2], [3, 4]) = [1, 2, 3, 4] concat(["a", "b"], ["c", "d"]) = ["a", "b", "c", "d"]
sort
Returns the list in sorted order.
sort([3, 1, 2]) = [1, 2, 3]
reverse
Returns the reversed list.
reverse(["green", "eggs", "ham"]) = ["ham", "eggs", "green"]
join
Returns the values of the list with the joiner placed between each of the values.
join(["a", "b", "c"], ", ") = "a, b, c" join(["dog", "go"], "") = "doggo"
split
Returns the list of values created by splitting a text input by a separator.
split("apple,pear,orange", ",") = ["apple", "pear", "orange"]
unique
Returns the list of unique values in the input list.
unique([1, 1, 2]) = [1, 2]
includes
Returns true if the list contains the specified value, and false otherwise.
includes(["a", "b", "c"], "b") = true includes([1, 2, 3], 4) = false
find
Returns the first item in the list for which the condition evaluates to true.
find(["a", "b", "c"], current == "b") = "b" find([1, 2, 3], current > 100) = Empty
findIndex
Returns the index of the first item in the list for which the condition is true.
findIndex(["a", "b", "c"], current == "b") = 1 findIndex([1, 2, 3], current > 100) = -1
filter
Returns the values in the list for which the condition is true.
filter([1, 2, 3], current > 1) = [2, 3] filter(["a", "b", "c"], current == "a") = ["a"]
some
Returns true if any item in the list satisfies the given condition, and false otherwise.
some([1, 2, 3], current == 2) = true some(["a", "b", "c"], current.length > 2) = false
every
Returns true if every item in the list satisfies the given condition, and false otherwise.
every([1, 2, 3], current > 0) = true every(["a", "b", "c"], current == "b") = false
map
Returns the list populated with the results of calling the expression on every item in the input list.
map([1, 2, 3], current + 1) = [2, 3, 4] map([1, 2, 3], current + index) = [1, 3, 5]
flat
Flattens a list of lists into a single list.
flat([1, 2, 3]) = [1, 2, 3] flat([[1, 2], [3, 4]]) = [1, 2, 3, 4]
id
Returns the id of the page. If no page is provided, returns the id of the page the formula is on.
id() id(prop("Relation").first())
equal
Returns true if both values are equal and false otherwise.
equal(1, 1) = true "a" == "b" = false
unequal
Returns false if both values are equal and true otherwise.
unequal(1, 2) = true "a" != "a" = false
let
Assigns a value to a variable and evaluates the expression using that variable.
let(person, "Alan", "Hello, " + person + "!") = "Hello, Alan!" let(radius, 4, round(pi() * radius ^ 2)) = 50
lets
Assigns values to multiple variables and evaluates the expression using those variables.
lets(a, "Hello", b, "world", a + " " + b) = "Hello world" lets(base, 3, height, 8, base * height / 2) = 12

Formula 2.0: What’s new with formulas

1. Multi-line Formulas

In the past, working with Notion's formulas meant navigating lengthy lines of code, which was tedious and prone to oversight.
Now, with multi-line editing, users can view formula segments as individual building blocks, making it easier to understand their interactions. This leads to more efficient troubleshooting and refinement of databases. Press Shift + Enter to break to a new line.

2. Rich Data outputs

Previously, Notion formulas could only reference text, numeric, and checkbox outputs. However, they now support displaying pages, dates, people, and lists as well.

3. Create your own variables with “LET”

In the past, Notion formulas lacked local variable support, requiring repeated calculations for the same value. With Formulas 2.0, you can now create and use variables, making formulas more concise and readable.

4. Retrieve workspace-level information from properties

You can access workspace-level information, including names and emails of tagged individuals, directly in your database without creating separate properties.
For instance, users can retrieve the user's full name and email using the "Created By" property, referencing them as prop("Created By").name() or prop("Created By").email(). This streamlines properties on larger databases, simplifying data retrieval without additional steps.

5. Reference Properties with related Databases

In Formulas 2.0, you no longer need to create rollups to establish properties in related Notion databases. Instead, use the prop() function, specifying the related database and property names.
For instance, in a Projects database related to Tasks, to reference the Status property of Tasks, use the formula: prop("Tasks").prop("Status"). This retrieves the Status value for the associated task.
Additionally, leverage functions like map(), filter(), and length() to manipulate data from the related database. This feature enhances formula complexity and dynamism, offering powerful capabilities.

How Notion Formula differs from Excel?

Notion formulas, like Excel, handle calculations in databases. However, they differ: Notion is page/database-focused, Excel is spreadsheet-centric. Notion formulas operate on columns, referencing properties for consistent application. Though Excel is more flexible, Notion formulas offer unique ways to enhance your workspace.

Wrapping up

In conclusion, understanding and using Notion's formulas unlocks a realm of efficiency and precision in your workspace.
In the ever-evolving realm of databases, calculations, and data manipulation, remember that formulas are more than mere strings of characters—they are your allies in creating intelligent, automated solutions.
Whether you're performing basic arithmetic or implementing complex conditional statements, view this guide as your compass. Keep experimenting with formulas and fully harness the capabilities of Notion.