quot; + price.toFixed(2), "")` to define a conditional with number formatting. - `file.name.lower()` to convert to lowercase. - `tags.contains("urgent")` to check if the tags list contains a value. - `due_date.format("YYYY-MM-DD")` to format a date. ## Use properties from linked notes Formulas can read properties from the notes a note links to. You can look up one value from a linked note, or roll up values from several linked notes into a total, a count, or a list. To read a linked note's properties, turn the link into a file with `asFile()`, then use `properties`. Links stored in properties, such as `project: "[[Website redesign]]"`, work this way directly. > [!warning] Results update when the note in the row changes > If you only edit a linked note, lookups and rollups in the base may not update until you reopen the base. ### Look up a value Show the `status` of the note linked in the `project` property: ```js project.asFile().properties.status ``` If the property can hold either one link or a list of links, wrap it in `list()` and take the first link: ```js list(project)[0].asFile().properties.status ``` ### Roll up values Add up the `hours` of every note linked in the `tasks` property: ```js tasks.map(value.asFile().properties.hours).reduce(acc + value, 0) ``` Count the linked notes whose `status` isn't "Done": ```js tasks.filter(value.asFile().properties.status != "Done").length ``` List the statuses of the linked notes, without duplicates: ```js tasks.map(value.asFile().properties.status).unique() ``` ### Roll up values from notes that link here To roll up values from the notes that link to a note, such as tasks that each link to their project, use `file.backlinks`: ```js file.backlinks.map(value.asFile().properties.hours).reduce(acc + value, 0) ``` `file.backlinks` is slow in large vaults. When you can, store the links in the note itself and roll them up with `map()` and `reduce()`, as shown above. ## Formula examples ### Calculate a deadline Set a project's due date as 2 weeks after the start date: ```js start_date + "2w" ``` ### Display overdue status Show "Overdue" if the due date has passed and status is not "Done": ```js if(due_date < now() && status != "Done", "Overdue", "") ``` ### Format currency Display a price with 2 decimal places and currency symbol: ```js if(price, "quot; + price.toFixed(2), "") ``` ### Count list items Count the number of items in a list property: ```js tasks.length ``` ### Calculate priority score Combine multiple factors into a priority score: ```js (impact * urgency) / effort ``` ### Combine text fields Create a full name from first and last name: ```js first_name + " " + last_name ``` ### Calculate total cost Multiply monthly cost by number of months owned: ```js monthlyUses * formula.Owned.round() ``` ## Data types Formulas work with different types of data: - **Strings** — Text enclosed in quotes: `"hello"` or `'world'` - **Numbers** — Numeric values: `42`, `3.14`, `(2 + 2)` - **Booleans** — True or false: `true`, `false` - **Dates** — Created with `date()`, `today()`, or `now()` - **Lists** — Collections of values: `[1, 2, 3]` - **Objects** — Key-value pairs: `{"name": "value"}` The output type of a formula is determined by the data and functions used. ## Reference other formulas Formulas can reference other formulas, creating derived calculations. For example, if you have a formula called `price_per_unit`: ```js price / quantity ``` You can reference it in another formula: ```js formula.price_per_unit * 1.1 ``` > [!warning] Avoid circular references > A formula cannot reference itself directly or indirectly through other formulas.