Notion VIP Logo
BulletproofA-to-ZConsultingThe Streamline
0
Subscribe

Notion's Versatile if() Function

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:

Notion if() Function: Pass/Fail

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:

Notion if() Function: Letter Grades

In this lesson, we'll explore the syntax of if(), nesting, and a widely applicable practical example.

The Syntax of if()

The if() function accepts three arguments:

1The 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

2The output if the test returns true.
Any expression—or combination of values, operators or functions that returns a single value.
Example: "Pass"

3The 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] is true,
return [Argument 2];
otherwise, return [Argument 3].

Given this syntax, you can understand the arguments of the pass/fail example:

  1. prop("Exam Score") >= .7
  2. "Pass"
  3. "Fail"

Here's the full formula:

if(prop("Exam Score") >= .7, "Pass", "Fail")

Nested if() Functions

As you now know, the if() function allows you define outputs for two conditions:

  1. When Argument 1 returns true
  2. When Argument 2 returns 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:

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:

  1. The value of Argument 2
  2. Argument 2 of the nested if()
  3. Argument 3 of the nested 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:

  1. Is "Dog" equal to "Cat"?
  2. If true, return "Dogs and cats are the same."
  3. If false:
    1. Is "Dog" equal to "Fish"?
    2. If true, return "Dogs are different from cats but the same as fish."
    3. If false, return "Dogs are different from cats and fish.".

Demo: Experience Level

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).

Notion if() Function: Experience Level

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:

  1. Is Completed Races at least 7?
  2. If true, return "Advanced".
  3. If false:
    1. Is Completed Races is at least 3?
    2. If true, return "Intermediate".
    3. Otherwise, return "Beginner".

Multi-Level Nesting

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:

Notion if() Function: Letter Grades

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:

  1. Is the exam score at least 90%?
  2. If true, return "A".
  3. If false:
    1. Is the exam score at least 80%?
    2. If true, return "B".
    3. If false:
      1. Is the exam score at least 70%?
      2. If true, return "C".
      3. If false:
        1. Is the exam score at least 60%?
        2. If true, return "D".
        3. If false, return "F".

Create the Eisenhower Matrix

What's the Eisenhower Matrix?

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:

Eisenhower Matrix

Apply It to Notion

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:

Eisenhower Matrix in Notion

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:

  1. Is the Urgency property "Urgent"?
  2. If true:
    1. Is the Importance property "Important"?
    2. If true, return "Do".
    3. If false, return "Delegate".
  3. If false (Urgency is not "Urgent"):
    1. Is the Importance property "Important"?
    2. If true, return "Schedule".
    3. If false, return "Eliminate".

Wrapping 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.

All-in on
the all-in-one
productivity app.
Subscribe →