Create unique page IDs in a database

Camille Ricketts
Jul 25 '19 · 3 min read · 1431 views
When working with databases, it's often useful for each item to have a unique ID. By combining a timestamp with various IF statements, you can create a formula that generates a unique ID for each page in your Notion database.

1. Create your database

In this example, we're going to use a database of tasks with the below properties and corresponding property types.
  • TaskTitle
  • Created TimeCreated Time
  • CreatorCreated By
  • CategorySelect
  • ProjectSelect

2. Assign a code to each property value

For the properties that contain fixed possible values and will remain constant, e.g., Select and Created By, establish a "code" for each possible value. Your code can be any character, including emojis, but we'll stick to digits for simplicity. Like this:


CreatorSteve Cook1
CreatorHoward Johnson2
CreatorAnna Huffington3
ProjectProject 11
ProjectProject 22
ProjectProject 33

3. Use this formula to generate codes

In your task database, you can automatically generate these codes depending on what you put in other property fields. Here's how that works with IF statements:


If Creator is "Steve Cook," output "1"; if Creator is "Howard Johnson," output "2"; if Creator is "Anna Huffington," output "3"; otherwise, output "0".
if(prop("Creator") == "Steve Cook", "1", if(prop("Creator") == "Howard Johnson", "2", if (prop("Creator") == "Anna Huffington", "3", "0")))


If Category is "Work," output "1"; if Category is "Personal," output "2"; otherwise, output "0".
if(prop("Category") == "Work", "1", if(prop("Category") == "Personal", "2", "0"))


If Project is "Project 1," output "1"; if Project is "Project 2," output "2"; if Project is "Project 3," output "3"; otherwise, output "0".
if(prop("Project") == "Project 1", "1", if(prop("Project") == "Project 2", "2", if(prop("Project") == "Project 3", "3", "0")))
Note: If for any reason there's no match, the code generated will be 0.

4. Convert time to decimals

Let's add a code based on the time that tasks were created to our existing code generated above for a truly unique ID. Use the timestamp() function to convert the created time for every task to decimals: timestamp( prop("Created Time") ).
  • To turn our timestamp into a string, let's use the format() function: format( timestamp( prop("Created Time") ) )

5. Combine formulas to get your page ID

To generate the combined ID, wrap individual formulas in parentheses and separate them with + signs. Copy this code by hovering and clicking Copy to Clipboard.
(if(prop("Creator") == "Steve Cook", "1", if (prop("Creator") == "Howard Johnson", "2", if ( prop("Creator") == "Anna Huffington", "3", "0"))))

+ (if(prop("Category") == "Work", "1", if(prop("Category") == "Personal", "2", "0")))

+ (if(prop("Project") == "Project 1", "1", if(prop("Project") == "Project 2", "2", if(prop("Project") == "Project 3", "3", "0"))))

+ (format(timestamp(prop("Created Time"))))

6. Add page ID property to your database

Back in your database, create a new column for page IDs and choose the Formula property type. Click any cell in this column, then paste the formula in Step 5 into the text box provided.

7. Get creative with characters

For simplicity, we used unseparated digits for our unique IDs, but you may opt to make your IDs more legible (and fun) by incorporating other character types. Here are some ideas:
  • Where we merged our formulas with +, you may choose to separate the properties represented in your Page ID with a dash: + "-" +.
  • By using letters rather than digits, you can quickly interpret the meaning of an ID. For example, we can use the initials of creators instead of a numerical code:
  • Emojis can be fun and useful as well, like these for distinguishing between categories:
Something we didn't cover? Message us in the app by clicking ? at the bottom right on desktop (or in your sidebar on mobile). Or email us at ✌️

Share on