if

Learn how to use the "if" operator in Notion formulas.

The if() operator allows you to write if-then statements within a Notion formula.

if([condition], ['then' expression], ['else' expression]) // Argument 1 must always return a Boolean value. // Arguments 2 and 3 must have a matching type. if(Boolean, string, string) if(Boolean, number, number) if(Boolean, Boolean, Boolean) if(Boolean, date, date)

If-then statements, also called conditional statements, contain:

  • The condition – a statement to be evaluated for truthiness (i.e. “is it true?”)
  • The “then” statement – a statement that is executed if the condition is true
  • The “else” statement – a statement that is executed if the condition is false

if() looks like a function in Notion, but it’s actually considered an operator because an if-then statement can be written with ? and : instead of the if() syntax.

This formula compares the output of a Select property called Type (which has a data type of String) with the string value “Mammal”. If the two are equal, it outputs true; otherwise, false.

if(prop("Type")=="Mammal",true,false)

Shorthand Syntax

If-then statements can also be written in a shorthand syntax. This uses ? and : as shorthand for if().

  • Everything left of the ? is the statement being evaluated.
  • Between ? and : is the output if the evaluated statement is true.
  • Right of the : is the output if the evaluated statement is false.
[condition] ? ['then' statement] : ['else' statement]

Here’s our example formula from above, re-written using shorthand:

prop("Type")=="Mammal" ? true : false

Taken together, ? and : form what’s called the conditional (or ternary) operator. It’s the only operator that takes in three operands, which are objects that are being operated on.

Most operators only work with two operands – for example:

  • 2 + 5 – the add (+) operator is working on 2 and 5

Check out the two formula properties in this example database; one uses the normal if-then syntax, while the other uses shorthand. You’ll see that their output is the same.

Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.
A new tool that blends your everyday work apps into one. It’s the all-in-one workspace for you and your team
thomasfrank.notion.site

Other formula components used in this example:

equal – Thomas Frank
thomasjfrank.com

Writing nested if-statements can become difficult in Notion’s default formula editor. If you’re writing a long formula, I recommend writing it in a free code editor such as VS Code, and then minifying it using Excel Formula Beautifier so it can be pasted into Notion (remove the = sign at the beginning of the formula output if it exists before pasting).

Notion does not support the “else if” statement that is supported by more popular scripting and programming languages, such as Javascript.

With an else if statement, you could write code like this (in Javascript):

/* This is Javascript code that won't work in a Notion formula */ if (x<13) { /* do one thing */ } else if (x<19) { /* do another thing */ } else { /* do the last thing */ }

In Notion, what we have to do instead is create nested if-then statements, like so:

if( prop("Age") < 13, "Child", if( prop("Age") < 19, "Teenager", "Adult" ) )
  • If the numeric value of a row’s Age property is less than 13, the then portion of the if-then statement is executed and the formula returns Child.
  • If not, the else statement is executed. In this case, our else statement is yet another if-then statement – hence, it’s a nested if-then statement.
    • Within the nested statement, the same logic applies. The condition is tested; if Age is less than 19, the then statement executes and outputs Teenager. If not, the else statement is executed and outputs Adult.

Here’s the logic tree for this nested if-then statement:

https://whimsical.com/ApM11ByUEfRA77SKwUFhMG //whimsical embed

Here’s a compressed version you can paste into a Notion formula property:

// if() syntax if( prop("Age") < 13, "Child", if( prop("Age") < 19, "Teenager", "Adult" ) ) // ? syntax prop("Age") < 13 ? "Child" : prop("Age") < 19 ? "Teenager" : "Child" // Notion will refrormat this to: (prop("Age") < 13) ? "Child" : ((prop("Age") < 19) ? "Teenager" : "Child")

Good to know: As you can see in the code block above, you can create nested statements with the conditional operators ? and : as well.
When using these, you don’t even need to add your own parentheses () to create your nested statement; Notion will add them after you exit the formula editor.

In the example database below, you can see the nested if-statements at work:

Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.
A new tool that blends your everyday work apps into one. It’s the all-in-one workspace for you and your team
thomasfrank.notion.site

Other formula components used in this example:

smaller – Thomas Frank
thomasjfrank.com
About the Author

My name is Thomas Frank, and I'm a Notion-certified writer, YouTuber, and template creator. I've been using Notion since 2018 to organize my personal life and to run my business and YouTube channel. In addition to this formula reference, I've created a free Notion course for beginners and several productivity-focused Notion templates. If you'd like to connect, follow me on Twitter.

🤔 Have an UB Question?

Fill out the form below and I’ll answer as soon as I can! ~Thomas

🤔 Have a Question?

Fill out the form below and I’ll answer as soon as I can! ~Thomas