Search

slice() | Beginner’s Guide to Notion Formula

post type
notion
tutorial
formula
status
published
author
created time
2024/10/23 12:53
description
Unlock the potential of the slice() function in Notion formulas to extract specific portions of your data! This comprehensive guide breaks down the structure of slice(), explains how it works, and provides practical examples. Learn how to manipulate lists effectively to streamline your data analysis and improve your workflow in Notion.
cover image
Frame 7.png
1 more property

This is your sign to try slice()

The slice() function lets you extract a specific section from a list.This function is especially useful when you want to work with a subset of items in your databases. In this blog post, we will explore the structure of the slice() function, break down how it works, and provide examples to demonstrate its utility.
For this guide, I referenced the Notion Formula documentation and added my own examples and explanations.

Summary

Name
Syntax
How it works
Example
slice()
slice(list, startIndex, endIndex?) or list.slice(startIndex, endIndex?)
Designed to return a portion of a list by specifying a start index (inclusive) and an optional end index (exclusive).
slice(["Inception", "The Matrix", "Pulp Fiction", "Interstellar", "The Shawshank Redemption"], 1, 3) → ["The Matrix", "Pulp Fiction"]

slice() Formula

How slice() works

The slice() function is designed to return a portion of a list by specifying a start index (inclusive) and an optional end index (exclusive).
The syntax for the slice() function is as follows:
slice(list, startIndex, endIndex?)
Notion Formula
복사
list.slice(startIndex, endIndex?)
Notion Formula
복사
Breaking it down
list: The collection of list or text from which you want to extract a portion.
startIndex: The index where extraction begins (using a zero-based index and inclusive).
endIndex: The index where extraction ends. This is an optional parameter (using a zero-based index, exclusive)

Examples of slice()

Search
example
description
formula
results
Slicing a list containg text values given startIndex and endIndex. - A new list will be returned, starting from the startIndex and including items up to, but not including, the endIndex.
slice(["Inception", "The Matrix", "Pulp Fiction", "Interstellar", "The Shawshank Redemption"], 1, 3) - In this example, the list features the top five movies (text value). - The startIndex is 1, meaning extraction starts at the second movie (zero-based indexing). - The endIndex is set to 3, so the returned items will include the movies from index 1 up to, but not including, index 3, which are The Matrix (index 1) and Pulp Fiction (index 2).
The Matrix,Pulp Fiction
Slicing a list containg text values given only startIndex. - A new list will be returned, starting from the startIndex all the way to the last item in the list.
slice(["Inception", "The Matrix", "Pulp Fiction", "Interstellar", "The Shawshank Redemption"], 2) - In this case, using the same list as in example 1, the startIndex is set to 2, meaning extraction begins at the third movie (zero-based indexing). Since the endIndex is not defined, the function will return items from the start index through to the last item in the list, which are Pulp Fiction (idx 2),Interstellar (idx 3),The Shawshank Redemption (idx 4)
Pulp Fiction,Interstellar,The Shawshank Redemption

Conclusion

The slice() function in Notion is a powerful tool that enables users to extract specified portions of lists effortlessly. By understanding its structure and how to implement it within your formulas, you can streamline the way you work with data in your Notion databases.
Thank you for reading this tutorial! If you found it helpful, be sure to check out shop for my beautiful templates, which I am confident enough to say are a game-changer Subscribe to my newsletter and feel free to follow me on my social media for updates!
Happy Notion(ing)!
Search