Notion Formula
Notion provides formula to dynamically calculate the value of a specific cell for a database.
If you navigate to your devtools and inspect the data, you'll see that this is how notion stores formula data. Lets take a look at an example of a simple notion formula:-
Parts of a formula argument#
type: This is thetypeof the formula argument, which could have the valuesfunction | symbol | constant | property | operator.result_type: The computated type of the argument, which has the following valuestext | checkbox | date | number.name: Indicates either a property, operator,function or symbol name, this is absent in constanttype
Formula Argument Result type#
Based on an arguments result_type it can be divided into the following types:
checkbox: This sort of arguments return a boolean value.text: This sort of arguments return a string value.date: This sort of arguments return a date valuenumber: This sort of arguments return a number value, which could either be integer or float.
Formula argument variants#
Based on an arguments type it can be divided into the following types:
- Symbol: A formula argument which is used to indicate fixed constant values like
true,false,eandpi - Property: A formula argument which is used to reference the value of another property of the schema
- Constant: A formula argument which is used to indicate a literal constant value like a number or a text.
- Function: A formula argument which is used to create a function.
- Operator: A separate representation of functions, by using symbols like
+,-instead ofaddandsubtractrespectively.
All variants have result_type
Each of the variants return an argument of a specific result_type.
Property Reference Argument#
The computed value of a property can be used as a formula argument. Inside notion it works by using the schema unit name inside the prop function, eg prop("Title"), would return the value stored in that cell.
This is how notion stores a property formula argument
Schema unit type coercion
Even though there are multiple schema unit types, all of them are coerced into the types supported by the result_type.
Nested Function Argument#
Functions gives formulas superpowers and thus notion provides a handful of them. Visit notion functions, to learn in details about everything function.
This is how notion stores a function formula argument
Constant Literal Argument#
A formula argument which is used to indicate a literal constant value like a number or a text.
Different from Symbol
Constants are different from symbols as symbols can only contain four possible values, while constants con contain infinity variants of values
This is how notion stores a constant formula argument
Operator Function Argument#
A separate representation of functions, by using operators like +, - instead of keywords like add and subtract respectively. Internally all operators except for the ternary operator ?: maps to a function.
This is how notion stores a constant formula argument
Symbol Literal Argument#
A formula argument which is used to indicate fixed constant values like true, false, e and pi
It contains the following values:-
true: A checkbox rt symbol, with nametruefalse: A checkbox rt symbol with namefalsee: A number rt symbol with nameepi: A number rt symbol with namepi
This is how notion stores a symbol formula argument
Variants of formula arguments#
Due to the existence of result_type and type, the following variants of arguments arises
Number x type variants#
- number x symbol: A
symboltypeargument that returnsnumberasresult_type. Eg:e | pi - number x constant: A
symboltypeargument that returnsnumberasresult_type. Eg:1 | 10 - number x property: A
propertytypeargument that returnsnumberasresult_type. Eg:prop("Number") - number x function: A
propertytypeargument that returnsnumberasresult_type. Eg:abs(1) - number x operator: A
propertytypeargument that returnsnumberasresult_type. Eg:1 + 1
Text x type variants#
- text x constant: A
constanttypeargument that returnstextasresult_type. Eg:"1" | "a" - text x property: A
propertytypeargument that returnstextasresult_type. Eg:prop("Text") - text x function: A
propertytypeargument that returnstextasresult_type. Eg:concat("a", "b") - text x operator: A
propertytypeargument that returnstextasresult_type. Eg:"b" + "a"
No symbol for text
Text result_type arguments does not have a symbol type
Checkbox x type variants#
- checkbox x symbol: A
symboltypeargument that returnscheckboxasresult_type. Eg:true | false - checkbox x property: A
propertytypeargument that returnscheckboxasresult_type. Eg:prop("Checkbox") - checkbox x function: A
propertytypeargument that returnscheckboxasresult_type. Eg:and(true, false) - checkbox x operator: A
propertytypeargument that returnscheckboxasresult_type. Eg:true and false
No constant for text
Checkbox result_type arguments does not have a constant type
Date x type variants#
- date x property: A
propertytypeargument that returnsdateasresult_type. Eg:prop("Date") - date x function: A
propertytypeargument that returnsdateasresult_type. Eg:now()
No constant,symbol for date
Date result_type arguments does not have constant and symbol variants