When you click inside the content area of a formula property, you’ll be presented with Notion’s formula editor.

The editor is split into three parts:

- The editor field. Formulas written here must be written in a single, unbroken line without line breaks or indentation.
- A scrollable list of all available properties, constants, operators, and functions. Clicking one will add it to your formula at the cursor’s current location.
- A context window the provides a description of the currently selected/hovered formula component. Also includes a syntax reference and one or more examples.

In addition to clicking formula components (constants, functions, etc), you can also start typing to automatically filter them. Hit enter when the one you want becomes highlighted.

When you’ve finished writing your formula, hit `Ctrl/⌘ + Enter` to exit the formula editor.

## Errors in Notion Formulas

If your formula contains an error, you won’t be able to save the changes you’ve made to it.

**Clicking away from the formula editor will result in your changes being lost, so make sure you copy your formula to your clipboard before doing so.**

When there is an error in your formula, you’ll see a description of it at the bottom of the formula editor.

Learn how to debug your formulas and fix errors:

## Writing Complex Formulas in VS Code

When you need to write a formula that’s more than a couple lines long, I highly recommend writing it first in a proper text editor such as Visual Studio Code first.

Writing your formulas in a true text editor will allow you to add indentation, comments, and other quality-of-life features that make you formulas easier to read and debug.

Notion formulas don’t have a specific syntax, so I recommend saving your formula files as JavaScript files with the `.js`

extension.

Note how I comment specific sections of my formula:

```
// First half of main else case - deal with opening hours
```

Notion formulas often require multiple levels of nested if statements, and these can get confusing and hard to keep track of. Adding comments above the function I’m calling helps me to understand my own formula code.

### Re-Formatting Formulas for Notion

Notion’s formula editor doesn’t support newlines or comments, so you can’t simply paste your formula from VS Code to Notion. If you try, your formula won’t work.

For this reason, we need to **re-format **formulas before they can be pasted into Notion:

- New lines must be removed
- Comments must be removed

Fortunately, you don’t have to do this manually! Instead, you can do a **find and replace **operation using a regular expression that removes all of these elements for you.

Here’s the expression (refer to the regular expressions guide if you want to understand how this works):

```
(\n[ ]{2,}|\n|[/]{2}[^\n]*)
```

Good to know: You can use text-snippet apps like TextExpander, Alfred (macOS), or Espanso to find this expression to an easy-to-type keyword. I use `nminify`

as my keyword to auto-paste this snippet with Alfred.

- Copy and paste your formula. We’ll compress one of the copies, leaving the other as an easy-to-read reference.
- Open the find and replace window with
`Ctrl/⌘ + F`

and paste the expression into the find field. - Paste in the expression above.
- Click the
**Use Regular Expression**button. - Select the entirety of your formula (just one of the copies)
- Click the
**Find in Selection**button. - Ensure the
**Replace**field is blank. - Click the
**Replace All**button.

Once done, your selected formula will be compressed and ready to paste into Notion: