In programming, a function is a reusable bundle or “chunk” of code. Functions have names which, when called elsewhere in the program, execute the function’s code.
Functions can also take in outside data (these are called arguments), and return new data.
In Notion formulas, you cannot define your own functions. However, Notion has provided many functions you can use.
For example, the length function takes in a string argument and outputs a number equal to the number of characters in that string.
length("Monkey D. Luffy") /* Output: 15 */
Code language: JavaScript (javascript)
Here’s a list of every function available for use in a Notion formula. Click a function to learn more about how it works and see more examples.
Function | Data Output Type | Example | Output |
---|---|---|---|
if | Any Data Type | if(1 + 1 == 2, true, false) | true |
ifs | Any Data Type | ifs(1 + 1 == 3, false, | true |
concat | List | concat(["Luffy","Zoro"] ,["Nami","Chopper"]) | Luffy, Zoro, Nami, Chopper |
join | String | join(["Luffy","Zoro","Nami","Chopper"], ", ") | Luffy, Zoro, Nami, Chopper |
slice | List | slice(["Luffy", "Zoro", "Nami", "Chopper"], 1, 2) | Zoro |
length | Number | length("Monkey D. Luffy") | 15 |
format | String | format(4) | 4 (as a string) |
toNumber | Number | toNumber("42") | 42 (as a number) |
contains | Boolean | contains("Monkey D. Luffy", "Luffy") | true |
replace | String | replace("Pogo","Po","Dog") | Doggo |
replaceAll | String | replaceAll("Dogs Dogs Dogs","Dogs","Cats") | Cats Cats Cats |
test | Boolean | test("Monkey D. Luffy", "Luffy") | true |
empty | Boolean | empty("") | true |
abs | Number | abs(-42) | 42 |
cbrt | Number | cbrt(64) | 4 |
ceil | Number | ceil(4.2) | 5 |
exp | Number | exp(2) | 7.389056098931 |
floor | Number | floor(4.2) | 4 |
ln | Number | ln(20) | 2.995732273554 |
log10 | Number | log10(1000) | 3 |
log2 | Number | log2(64) | 6 |
max | Number | max(3,5,4) | 5 |
min | Number | min(4,1,9,-3) | -3 |
round | Number | round(4.5) | 5 |
sign | Number | sign(-5) | -1 |
sqrt | Number | sqrt(16) | 4 |
dateStart | Date | dateStart(prop("Date")) | August 18, 2022 |
dateEnd | Date | dateEnd(prop("Date")) | August 25, 2022 |
now | Date | now() | August 18, 2022 2:10 PM |
today | Date | today() | October 6, 2024 |
timestamp | Number | timestamp(now()) | 1660853460000 |
fromTimestamp | Date | fromTimestamp(1656012840000) | June 23, 2022 1:34 PM |
dateAdd | Date | dateAdd(now(),3,"months") | November 18, 2022 2:11 PM |
dateSubtract | Date | dateSubtract(now(),3,"months") | May 18, 2022 2:11 PM |
dateBetween | Number | dateBetween(now(),prop("Date"),"days") | 9 |
formatDate | String | formatDate(now(), "MMMM DD YYYY") | August 18 2022 |
minute | Number | minute(now()) | 9 |
hour | Number | hour(now()) | 14 |
day | Number | day(now()) | 4 |
date | Number | date(now()) | 18 |
month | Number | month(now()) | 7 |
year | Number | year(now()) | 2022 |
id | String | id() | c5d67d15854744869cc4a062fb7b1377 |
substring | String | substring("Dangerfield", 0, 6) | Danger |
match | List | match("Thomas 123 Frank 321", "\d+") | 123, 321 |
lower | String | lower("Monkey D. Luffy") | monkey d. luffy |
upper | String | upper("Nami") | NAMI |
repeat | String | repeat("๐", 5) | ๐๐๐๐๐ |
padStart | String | padStart("hello", 8, ".") | …hello |
padEnd | String | padEnd("hello", 8, ".") | hello… |
link | String | link("Not a Rick Roll", "https://www.youtube.com/watch?v=dQw4w9WgXcQ") | Not a Rick Roll |
style | String | style("Listen, Bub", "b", "i",) | Listen, Bub |
unstyle | String | unstyle("Listen, Bub", "i",) | Listen, Bub |
sum | Number | sum(1, 2, 3) | 6 |
median | Number | median(1, 2, 3) | 2 |
mean | Number | mean(3, 12, 30) | 15 |
week | Number | week(now()) | 37 |
dateRange | Date Range | dateRange(parseDate("2023"), parseDate("2023-02")) | January 1, 2023 โ February 1, 2023 |
parseDate | Date | parseDate("2023-01-01") | January 1, 2023 |
name | String | prop("Created By").name() | Thomas Frank |
String | prop("Created By").email() | [email protected] | |
at | Any Data Type | at([1, 2, 3], 1) | 2 |
first | Any Data Type | first([1, 2, 3]) | 1 |
last | Any Data Type | last([1, 2, 3]) | 3 |
sort | List | sort([2, 3, 1]) | 1, 2, 3 |
reverse | List | reverse([1, 2, 3]) | 3, 2, 1 |
split | List | split(“One-Two-Three”, “-“) | One, Two, Three |
unique | List | unique([1, 1, 2]) | 1, 2 |
includes | Boolean | includes(["Luffy", "Zoro", "Nami", "Chopper"], "Zoro") | true |
find | Any Data Type | find(["a", "b", "c"], currentValue == "b") | b |
findIndex | Number | findIndex(["a", "b", "c"], currentValue == "b") | 1 |
filter | Any Data Type | filter([1, 2, 3], currentValue > 1) | 2, 3 |
some | Boolean | some([1, 2, 3], currentValue == 2) | true |
every | Boolean | every([1, 2, 3], currentValue > 0) | true |
map | Any Data Type | map([1, 2, 3], currentValue + 1) | 2, 3, 4 |
flat | List | flat([[1, 2], [3, 4]]) | 1, 2, 3, 4 |
let | All Data Types | let(a, 2, a + 2) | 4 |
lets | All Data Types | lets(a, 1, b, 2, a + b) | 3 |
Functions as Arguments
Functions can accept other functions as arguments, so long as the inner function outputs the data type that the outer function requires.
Here are a couple examples:
1932.substring(0, 2) /* Output: 19 */
---
/* Get the century name (e.g. "20th") from a year (expressed as a number) */
1932.substring(0, 2).toNumber().add(1) + "th" /* Output: 20th */
/* Expanded form */
1932
.substring(0, 2)
.toNumber()
.add(1) + "th"
Code language: JavaScript (javascript)
For more examples, see the example databases for most of the functions. The majority in this reference use other functions as arguments in order to do useful things. To start, I’ll recommend checking out the format function’s example database.