Notion formulas allow you to manipulate text strings, numbers, and dates directly inside databases. The slice() function extracts a portion of a text string based on a starting and optional ending position. When you need to pull a first name from a full name, isolate a domain from an email address, or grab a specific set of characters from a code, slice() is the right tool. This article explains how the function works, provides step-by-step examples, and covers common mistakes to avoid.
Key Takeaways: How to Use slice() in Notion Formulas
- slice(property, start, end) syntax: Extracts characters from a text property using zero-based indexes;
endis optional and exclusive. - Negative index values: Count from the end of the string;
-1is the last character,-2is the second-to-last, and so on. - Combine with other functions like length() and find(): Use dynamic positions to slice variable-length strings such as email domains or file extensions.
What the slice() Function Does in a Notion Formula
The slice() function returns a substring from a text property or a formula result. It uses zero-based indexing, meaning the first character is at position 0. The syntax is slice(property, start, end) where property is the text to slice, start is the index of the first character to include, and end is the index of the character to stop before. If you omit end, the function returns all characters from start to the end of the string.
For example, slice("Notion", 0, 3) returns "Not". The characters at positions 0 (N), 1 (o), and 2 (t) are included, but position 3 (i) is not. This behavior is standard in many programming languages and is often called a “half-open” range.
Prerequisites for using slice():
- You need a Notion database with at least one text property or a formula that outputs text.
- The function works on text strings only. If you apply it to a number or date, Notion converts the value to text first.
- You must understand zero-based indexing to get the correct results.
Steps to Write a slice() Formula in a Notion Database
Follow these steps to add a formula that uses slice() to a Notion database property.
- Open the database and add a formula property
Navigate to the Notion page that contains your database. Click the+button in the last column header of the table view. Select Formula from the property type list. Name the property, for example “First Name” or “Domain”. - Click inside the formula editor
A new empty formula field appears. Click it to open the formula editor panel on the right side of the window. The editor provides a text input area and a list of available functions. - Type the slice() function
Enterslice(. The editor shows a tooltip explaining the parameters:string,start, andend(optional). - Insert the source property
Click the Insert a property button in the editor, or typeprop("Property Name")manually. ReplaceProperty Namewith the exact name of the text property you want to slice. - Specify the start and end positions
After the source property, type a comma and the start index. For example,, 0starts at the first character. Type another comma and the end index, for example, 5. Close the function with a closing parenthesis. The complete formula looks likeslice(prop("Full Name"), 0, 5). - Click Done to save the formula
The formula processes for every row in the database. If the source property is empty, the formula returns an empty string. Review the results to verify the slice worked as expected.
Example: Extract the First Word from a Full Name
Assume you have a property called “Full Name” that contains values like “John Smith”. To extract only “John”, use slice(prop("Full Name"), 0, 4). The space at position 4 is the end index, so the result is the first four characters: J, o, h, n.
Example: Use Negative Index to Get the Last 3 Characters
If the property “Code” contains values like “XYZ-123”, you can get the last three digits with slice(prop("Code"), -3). The start index -3 tells Notion to begin three characters from the end. Because no end index is given, the slice goes to the end of the string. The result is “123”.
Example: Slice a Dynamic Length String Using find()
To extract the domain from an email address like “user@example.com”, use slice(prop("Email"), find("@", prop("Email")) + 1). The find() function returns the position of the @ symbol. Adding 1 moves the start index to the first character after @. The result is “example.com”.
Common Mistakes When Using slice() in Notion Formulas
I Get an Empty Result or Wrong Characters
This usually happens when the start or end index is out of range. If start is greater than or equal to the length of the string, slice() returns an empty string. If end is less than start, the result is also empty. Check the length of your source text using the length() function: length(prop("Text")). Ensure the start index is less than the total length.
The Formula Returns Text Instead of a Number
The slice() function always returns a text result. If you need a number, wrap the slice with the toNumber() function. For example, toNumber(slice(prop("Code"), -3)) converts the extracted substring to a number that you can use in math formulas.
Spaces or Special Characters Throw Off the Slice
The slice index counts every character, including spaces, punctuation, and emoji. A single emoji character counts as one index position, but some emoji sequences (like flags or skin-tone modifiers) may count as multiple characters. Test with a known string first to confirm the exact positions.
slice() vs left() and right() Functions Compared
| Item | slice() | left() and right() |
|---|---|---|
| Description | Extracts a substring from any start to any end position | left() extracts from the start; right() extracts from the end |
| Parameters | slice(text, start, end) where end is optional |
left(text, count) and right(text, count) |
| Negative indexes | Supported — counts from the end of the string | Not supported — only positive integers for count |
| Use case | Extracting a middle portion, dynamic slicing with find() | Getting a fixed number of characters from the start or end |
The left() function is simpler when you always want the first N characters. For example, left(prop("Name"), 1) returns the first initial. The right() function is best for the last N characters, like right(prop("Phone"), 4) to get the last four digits. Use slice() when you need a middle section or when the start position depends on another function like find().
You can now write slice() formulas to extract any part of a text string in your Notion databases. Start by testing with a simple fixed-index slice, then move to dynamic slices using find() or length(). For advanced text manipulation, combine slice() with replace() and concat() to build complex output strings. Remember that indexes are zero-based and the end index is exclusive.