Skip to content

Formulas

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.

  1. 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 (…).
  2. In Pick column type, choose Formula under Calculated.
  3. Type a Name and the Formula. Use Insert a property to add a property’s name.
  4. Look at the Formula preview. It shows the result for the first records while you type.
  5. 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.

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
  • Properties: write the property’s name, such as price. If the name has spaces or other characters, write note["due date"].
  • Other formulas: formula.total reads the formula column total.
  • The file: file.name, file.folder, file.mtime, file.tags and the other file fields.
  • This Base: this.file is the file of the .base file itself, such as this.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.
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.

  • date - date is a duration. Read its parts with .days, .hours and the other duration fields.
  • date + duration and date - duration move a date: due + "1 week", start - duration("3 days").
  • A date has the fields year, month, day, hour, minute, second and millisecond.
  • 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);

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.

  • 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.