Before exploring Notion's if()
function, please ensure your familiarity with Formula Fundamentals. For all lessons in a natural sequence, along with videos, functional demos, practical exercises and certification questions, join Notion A-to-Z.
The if()
function is among Notion's most versatile and frequently used functions. It allows you to specify outcomes for multiple conditions. In other words:
If
[Condition]
, return[A]
; otherwise, return[B]
.
For example, you can test whether an exam score is 70% or greater, then return "Pass"
or "Fail"
accordingly:
By nesting if() functions, you can define outcomes for more than two conditions. Therefore, you can also return the letter grade of each exam score:
In this lesson, we'll explore the syntax of if(), nesting, and a widely applicable practical example.
if()
The if()
function accepts three arguments:
1 — The condition.
An expression that returns a boolean (true
or false
). This is typically a test performed with a comparison operator, such as >
.
Example: prop("Exam Score") >= .7
2 — The output if the test returns true
.
Any expression—or combination of values, operators or functions that returns a single value.
Example: "Pass"
3 — The output if the test returns false
.
Another expression, for which the returned data type matches that of Argument 2.
Example: "Fail"
Therefore, we can rephrase our sentence:
If
[Argument 1]
istrue
,
return[Argument 2]
;
otherwise, return[Argument 3]
.
Given this syntax, you can understand the arguments of the pass/fail example:
prop("Exam Score") >= .7
"Pass"
"Fail"
Here's the full formula:
if(prop("Exam Score") >= .7, "Pass", "Fail")
if()
FunctionsAs you now know, the if()
function allows you define outputs for two conditions:
true
false
You can specify additional conditions by using "inner" if()
functions as Argument 2 or 3 of the "outer" if()
function. This creates a sort of choose-your-own-adventure scenario, where one or both possible outcomes of the first test can be another test with its own possible outcomes.
This is best visualized using our Code
block strategy for composing complex formulas, where each argument is indented on its own line. In this demonstration, Arguments 2 and 3 of the outer if()
function are nested if()
functions, each of which contains its own three arguments:
if(
[Test 1],
if(
[Test 2],
[Output 2.2],
[Output 2.3]
),
if(
[Test 3],
[Output 3.2],
[Output 3.3]
)
)
Here's how you might articulate the above formula in natural language:
[Test 1]
is true
:[Test 2]
is true
,[2.2]
;[2.3]
.[Test 1]
is false:[Test 3]
is true,[3.2]
;[3.3]
.This provides four possible outputs: 2.2
, 2.3
, 3.2
, and 3.2
. The two nested if()
functions split the outputs of the outer if()
. If we used a nested if()
only for Argument 3, we'd have three possible outputs:
if()
if()
Here's a functional formula with one nested if()
, followed by an explanation:
if(
"Dog" == "Cat",
"Dogs and cats are the same.",
if(
"Dog" == "Fish",
"Dogs are different from cats but the same as fish.",
"Dogs are different from cats and fish."
)
)
In natural language, here's how the formula executes:
"Dog"
equal to "Cat"
?true
, return "Dogs and cats are the same."
false
:"Dog"
equal to "Fish"
?true
, return "Dogs are different from cats but the same as fish."
false
, return "Dogs are different from cats and fish."
.The example below references the Completed Races property to designate each person as "Advanced"
(7+ races), "Intermediate"
(3–6 races) or "Beginner"
(0–2 races).
Here's the formula, followed by an explanation:
if(
prop("Completed Races") >= 7,
"Advanced",
if(
prop("Completed Races") >= 3,
"Intermediate",
"Beginner"
)
)
In natural language, here's how the formula executes:
7
?true
, return "Advanced"
.false
:3
?true
, return "Intermediate"
."Beginner"
.To add even more conditions and possible outcomes, you can nest if()
functions within other nested if()
functions. That's how our letter grade example works: it contains an if()
within an if()
within an if()
within an if()
. Here's another look:
Here's the formula, followed by an explanation:
if(
prop("Exam Score") >= .9,
"A",
if(
prop("Exam Score") >= .8,
"B",
if(
prop("Exam Score") >= .7,
"C",
if(
prop("Exam Score") >= .6,
"D",
"F"
)
)
)
)
Here's how to articulate the execution:
true
, return "A"
.false
:true
, return "B"
.false
:true
, return "C"
.false
:true
, return "D"
.false
, return "F"
.The Eisenhower Matrix is a popular method of prioritizing tasks. It prescribes one of four actions according to the urgency and importance of each task:
In Notion, a Tasks database can include Select
properties for urgency and importance. Based on the values of those properties, an if()
function can return the corresponding action from the Eisenhower Matrix:
Here's the formula, followed by an explanation:
if(
prop("Urgency") == "Urgent",
if(
prop("Importance") == "Important",
"Do",
"Delegate"
),
if(
prop("Importance") == "Important",
"Schedule",
"Eliminate"
)
)
In natural language, here's how the arguments execute:
"Urgent"
?true
:"Important"
?true
, return "Do"
.false
, return "Delegate"
.false
(Urgency is not "Urgent"
):"Important"
?true
, return "Schedule"
.false
, return "Eliminate"
.if()
The formula above will return an unintended value if the Urgency or Importance property is blank. In such cases, we want to return an empty text string
rather than an action from the Eisenhower Matrix. To do so, the formula can initially test for empty values in Urgency and Importance.
When working with formulas, you'll often encounter instances where you need to account for special circumstances, such as incomplete properties. You can easily test for these circumstances by "wrapping" your formula in an outer if()
function. In other words, your full formula becomes Argument 3 of a containing if()
.
The formula below places our initial Eisenhower formula within a containing if()
as Argument 3. Argument 1 uses lenght()
functions within an or()
function to test whether the Urgency or Importance property is blank. If true
, it returns ""
; otherwise, it proceeds with our original formula.
if(
or(
length(prop("Urgency")) == 0,
length(prop("Importance")) == 0
),
"",
if(
prop("Urgency") == "Urgent",
if(
prop("Importance") == "Important",
"Do",
"Delegate"
),
if(
prop("Importance") == "Important",
"Schedule",
"Eliminate"
)
)
)
If you hit any roadblocks in your work with if()
, I'm all ears on Twitter @WilliamNutt.