Calculate a value for each record with a formula column, in the formula language of Obsidian Bases.
A formula column calculates a value for each record from its properties and its file. BaseStudio uses the formula language of Obsidian Bases and adds functions listed in the formula reference. A formula that uses a BaseStudio-only function may not work in Obsidian.
Add a formula column
Section titled “Add a formula column”- Select Add column (+) after the last column of a table, or open the arrow next to New record and select New formula. On a phone, use More table actions (…).
- In Pick column type, choose Formula under Calculated.
- Type a Name and the Formula. Use Insert a property to add a property’s name.
- Look at the Formula preview. It shows the result for the first records while you type.
- Select Add formula. When you edit a formula later, the button is Save formula.
To change a formula later, open the menu of its column and select Edit formula.
Examples
Section titled “Examples”| Formula | Result |
|---|---|
price * quantity |
The total of two number properties |
if(done, "Finished", "Open") |
A text that depends on a checkbox |
file.name |
The name of the record’s note |
due.format("YYYY-MM-DD") |
A date property as text |
(today() - start).days |
The number of days since a date |
due < today() && !done |
True for a late task |
tags.filter(value.startsWith("area/")) |
The tags that start with area/ |
file.hasTag("project") |
True for a note with the tag #project |
Values
Section titled “Values”- Properties: write the property’s name, such as
price. If the name has spaces or other characters, writenote["due date"]. - Other formulas:
formula.totalreads the formula columntotal. - The file:
file.name,file.folder,file.mtime,file.tagsand the other file fields. - This Base:
this.fileis the file of the.basefile itself, such asthis.file.folder. - Literals: text in
"double"or'single'quotes, numbers,true,false,null, lists such as[1, 2], and regular expressions such as/^INV-\d+$/i.
Operators
Section titled “Operators”| Operator | Meaning |
|---|---|
+ - * / % |
Arithmetic. + with text joins the texts. |
== != |
Equal, not equal |
< > <= >= |
Compare numbers, dates and texts |
&& || ! |
And, or, not |
if(test, yes, no) |
yes when test is true, else no |
if can leave out no. Then the result is null when the test is false.
Dates and durations
Section titled “Dates and durations”date - dateis a duration. Read its parts with.days,.hoursand the other duration fields.date + durationanddate - durationmove a date:due + "1 week",start - duration("3 days").- A date has the fields
year,month,day,hour,minute,secondandmillisecond. today()is today with no time.now()is the current date and time.
filter, map and reduce take an expression that uses value (the item), index (its position) and, in reduce,
acc (the result so far):
scores.filter(value >= 50).length;prices.map(value * 1.2);prices.reduce(acc + value, 0);Functions
Section titled “Functions”See the formula function reference for every function that BaseStudio supports. A function that BaseStudio does not support shows an error in the cell. It does not guess a result.
Errors and limits
Section titled “Errors and limits”- A formula with an error shows the error message in its cells.
- A formula can be up to 16 KB long. It can use up to 10,000 calculation steps for each record.
- When a value has a different type than its column, BaseStudio marks the cell.
For lookups and rollups through link columns, see Relations.