The if()
function is among the most versatile and widely used functions in Notion and other spreadsheet tools. By allowing you to return values according to specified conditions, it bolsters your ability to automate properties and streamline your operation.
This guide presents the fundamentals of if()
, then explores a few practical examples whose principles can be applied widely. For your reference, those examples are available as a template on Notion Market.
If you're new to Notion functions, consider starting with Meet Notion's Formula Property and Formulas for Work: Part 1. If you just need a refresher, here's an overview:
numbers
, strings
(text), dates
or booleans
(true or false).if()
function?The if()
function is a special type of function that returns values based on specified conditions. Simply stated: if Condition A is true
, return Value X; otherwise, return Value Y.
Take an exam score, for example: If Score is at least 80%, return Pass; otherwise, return Fail.
To accomplish this, if()
accepts three arguments:
boolean
(true or false)true
false
The first argument typically compares values using comparison operators, such as >
, ≥
, ==
and !=
. Almost always, one or more of the compared values is a reference to another property. In our example, the exam score is drawn from another property in the database. Therefore, if()
takes these arguments:
prop("Score") ≥ 8
"Pass"
"Fail"
Here's the full formula:
if( prop("Score") ≥ 8, "Pass", "Fail" )
For the first argument, you can create complex comparisons using the and()
and or()
functions. So long as it evaluates to a single true
or false
, you can make the expression as elaborate as needed.
Additionally, you can specify more than two conditions by "nesting" if()
functions. I illustrate this in the following examples.
By using "child" if()
functions within the arguments of "parent" if()
functions, we can create more than two possible outcomes. This is known as "nesting." Building on the previous example, this allows us to assign a letter grade to each exam score.
Argument 3 of if()
specifies the value to return if Argument 1 is false
. If we use an inner if()
statement as Argument 3, we can add an additional condition. Consider this series of conditions:
We can construct this with an if()
function as the third argument of outer if()
function:
if(
prop("Score") >= .9,
"A",
if(
prop("Score") >= .8,
"B",
"C"
)
)
This format makes it easy to identify arguments and nested functions. To paste into Notion, eliminate the line breaks by pasting into your browser's address bar, then re-copying.
"C" is the third argument of the nested if()
. Therefore, you can create scenarios for "D" and "F" by adding further nested if()
functions:
if(
prop("Score") >= .9,
"A",
if(
prop("Score") >= .8,
"B",
if(
prop("Score") >= .7,
"C",
if(
prop("Score") >= .6,
"D",
"F"
)
)
)
)
At each step, we know that all previous conditions are false
.
For dashboards and filtered database views, it's helpful to assign a status to projects, such as "Planned," "In Progress" and "Complete."
Using Relation and Rollup properties, you can automatically calculate the progress of a project as a percentage of its completed tasks. An if()
function can then reference that "Progress" property to populate "Status."
If Progress is 0%, Status is "Planned." If Progress is 100%, Status is "Complete." Otherwise, Status is "Active."
With just one nested if()
, we can compose this formula:
if(
prop("Progress") == 0,
"Planned",
if(
prop("Progress") == 1,
"Complete",
"Active"
)
)
The Eisenhower Matrix is a system of prioritizing tasks based on their importance and urgency. You designate each task as either "Important" or "Not Important," and "Urgent" or "Not Urgent," and the matrix instructs you to "Do," "Schedule," "Delegate" or "Eliminate."
With a Notion database and the if()
function, you can automate this process and sort your tasks by priority.
A database of tasks has a Select
property called "Importance" with two options: "Important" and "Not Important." Another Select
property, "Urgency," has the options "Urgent" and "Not Urgent."
A Formula
property, "Priority," references Impact and Urgency to return an action for each task. In natural language, the formula says:
To achieve this, we us an if()
function for Argument 2 and Argument 3 of an outer if()
:
if(
prop("Urgency") == "Urgent",
if(
prop("Importance") == "Important",
"Do",
"Delegate"
),
if(
prop("Importance") == "Important",
"Schedule",
"Eliminate"
)
)
To keep the Priority property of unpopulated tasks empty, we can use the full formula above as Argument 3 of an outer if()
that uses or()
and empty()
to test whether Urgency or Importance is blank:
if(
or( empty(prop("Urgency")), empty(prop("Importance"))),
"",
if(
prop("Urgency") == "Urgent",
if(
prop("Importance") == "Important",
"Do",
"Delegate"
),
if(
prop("Importance") == "Important",
"Schedule",
"Eliminate"
)
)
)
Once prioritized, it's helpful to sort tasks by their priority. To so, we can add another Formula property, Priority Order
, which returns a number for each possible priority.
In natural language:
1
;2
;3
;4
.Here's the formula:
if(
prop("Priority") == "Do",
1,
if(
prop("Priority") == "Delegate",
2,
if(
prop("Priority") == "Schedule",
3,
4
)
)
)
You can then sort your tasks by Priority Order (ascending), then hide the property.
Questions? Tweet @WilliamNutt.