Relations, Database

Notion Formula: Automate Sleep Database With Relations And Rollups

Screen Shot 2020-06-25 at 9.27.25 AM.png

๐Ÿ›Œ Multi-Database Formula

I want to show how one can use multiple databases to create a conditional formula in Notion. For instance, the following example uses properties from a "Tasks" database and returns a formula inside a separate "Sleep Tracker."

More specifically, under the conditions of a tag associated with a "task," properties for an "alarm set" to wakeup and "unwinding" time before bed is altered. To do this I use relational and rollup properties.

Let's Begin With Tasks

Screen Shot 2020-06-25 at 9.22.06 AM.png

In the task database there is only three properties (Name, Priority and Deadline). We want to connect 'Name' and 'Priority' into a separate sleep tracker.

The Sleep Tracker

In order to connect tasks, we need to first create a relation property and connect that property to the 'Tasks' database.

Screen Shot 2020-06-24 at 3.31.58 PM.png

Next, configure a rollup property like so:

Screen Shot 2020-06-24 at 3.34.22 PM.png

Original Formulas

Looking at the formulas of the "Sleep Tracker," there are three distinct properties:

  • Unwinding โ†’ Time to unwind before bed (1 hour before "Latest Sleep Time") โ†’ dateSubtract(prop("L.Sleep Time"), 1, "hours")

  • L. Sleep Time โ†’ Latest time to go to sleep dependent upon "Alarm Set" (7 hours before alarm) โ†’ dateSubtract(prop("Alarm Set"), 7, "hours")

  • Alarm Set โ†’ Time to wake up the next morning (6:00 AM) โ†’ dateAdd(prop("Date"), 30, "hours")

Screen Shot 2020-06-24 at 3.36.05 PM.png

New Formulas With Inclusion Of Tasks Database

Using the new properties, here are modified formulas that give the original formulas more nuance.

  • Unwinding โ†’ if(contains(prop("Priority"), "Essay"), concat("โญ•๏ธ Look Over Essay" + " -- " + format(dateSubtract(prop("L.Sleep Time"), 1, "hours"))), if(contains(prop("Priority"), "Exam"), concat("โญ•๏ธ Meditate" + " --" + format(dateSubtract(prop("L.Sleep Time"), 1.5, "hours"))), if(day(prop("Date")) == 5, "๐Ÿ›Œ Flexible", format(dateSubtract(prop("L.Sleep Time"), 1, "hours")))))

  • L. Sleep Time โ†’ dateSubtract(prop("Alarm Set"), 7, "hours")

  • Alarm Set โ†’ (day(prop("Date")) == 5) ? dateAdd(prop("Date"), 32.5, "hours") : dateAdd(prop("Date"), 30, "hours")

Screen Shot 2020-06-25 at 9.23.13 AM.png

Video Tutorial