The IF function is one of the most commonly used functions in Notion. It is a conditional statement that evaluates whether a condition is met and returns different values based on the result. Here’s a brief overview of how to use the IF function:
IF Function Syntax
-
- The IF function syntax is as follows:
if([condition], [value if true], [value if false])
. - The condition should be a Boolean value (either true or false). If the condition is true, it returns the 1 value. If the condition is false, it returns the 2 value.
- Note: The data types of the first and second values must be the same. They should follow the syntax:
if(Boolean, Boolean, Boolean)
if(Boolean, String, String)
if(Boolean, Number, Number)
if(Boolean, Date, Date)
- The IF function syntax is as follows:
Although the IF function looks like a function, it is actually an operator in Notion, specifically a ternary operator, which means it requires three arguments to work.
IF Function Use Cases
-
- Comparing Strings
Suppose we have a task list with tasks of different urgency levels, such as “urgent” and “general”.
Now, we want to create a new numeric property to determine the urgency of the current task. If it’s urgent, the value is 2; if it’s general, the value is 1. We can use the IF function to determine whether the urgency of the task is “urgent”. If it is, it returns 1; otherwise, it returns 2.
The formula is as follows: if(prop("Urgency") == "Urgent", 2, 1)
.
-
- Comparing Numeric Values
The IF function can also compare numeric values. We can create a new column. If the urgency level is greater than 1, it returns true; otherwise, it returns false.
The formula is as follows: if(prop("Urgency (Numeric)") > 1, true, false)
.
IF Function Shorthand Syntax
The IF function has a shorthand syntax that doesn’t require writing in English. You only need to use the symbols ? and :. The shorthand syntax is as follows: [condition] ? [value if true] : [value if false]
.
-
- The left side of the ? is the first argument, which is the condition to determine the truth.
- The value between ? and : is the second argument. If the condition is true, it returns the second argument.
- The right side of the : is the third argument. If the condition is false, it returns the third argument.
The following two formulas are both IF functions, and they express the same meaning:
-
- Default syntax:
if(prop("Urgency (Numeric)") > 1, true, false)
- Shorthand syntax:
(prop("Urgency (Numeric)") > 1) ? true : false
- Default syntax:
Advanced Usage: Nested IF
In actual work, the usage of the IF function can be more complex, and it may be necessary to nest more IF functions within an IF function. For example, in the following table, the urgency of the tasks is divided into three levels: very urgent, urgent, and general.
We want to create a new column to assign a numeric value based on the urgency of the task: very urgent – 3, urgent – 2, general – 1. The nested IF function used here is as follows: if(prop("Urgency") == "Very Urgent", 3, if(prop("Urgency") == "Urgent", 2, 1))
.
In conclusion, the IF function in Notion is a powerful tool that can be used to create complex conditional statements, making your work in Notion more efficient and organized.