Boolean and Boolean and(Boolean, Boolean) Boolean && Boolean
And is useful for testing that two or more things are true.
Good to know: Notion is no longer picky, so
And now also work.
You can also use the function version,
true and true /* Output: true */ true && false /* Output: false */ and(1 > 0, 0 < 4) /* Output: true */ if(true and true, "Happy", "Sad") /* Output: "Happy" */ if(true and false, "Happy", "Sad") /* Output: "Sad" */ if(5 > 4 and 1 < 3, true, false) /* Output: true */ if(length("Monkey D. Luffy") > 5 and length("Monkey D. Luffy") < 100, true, false) /* Output: true */
and operator can also be chained together multiple times:
4 > 2 and 3 < 4 and 5 > 2 and 7 == 7 ? true : false /* Output: true */
The example database below shows a list of shore leave requests from a pirate crew. The captain will only approve a request if both are true:
- The request doesn’t fall on one of that crew member’s watch duty days
- The crew member has less than $10,000 in gambling debt
The Approved? formula uses the and operator to ensure that both of these conditions are true. If so, it’ll output
true and the request will be approved. If not, it’ll output
false and the request will be denied.
// Compressed if(prop("Gambling Debt") < 10000 and not contains(prop("Watch Duty Days"), formatDate(prop("Request Date"), "dddd")), true, false) // Expanded if( prop("Gambling Debt") < 10000 and not contains( prop("Watch Duty Days"), formatDate( prop("Request Date"), "dddd" ) ), true, false )
This formula uses an if statement to check that both of the captain’s conditions are true:
- The first operand checks that the crew member’s gambling debt is
- The second operand checks the request date against the crew member’s assigned watch days:
- The contains function checks to see if the Request Date’s day of the week is contained in the Watch Duty Days list for each row.
- The formatDate function uses the Moment.js string
ddddto convert the Request Date into a named day of the week (i.e. “Wednesday”) so it can be compared against the tags in the Watch Duty Days property.
- Finally, the not operator negates the boolean output of the
contain()function, ensuring the
andoperator only returns
trueif the Request Date DOESN’T match an assigned Watch Duty Day.