Search

filter() | Beginner’s Guide to Notion Formula

post type
notion
tutorial
formula
status
published
author
created time
2024/10/23 12:53
description
Discover how to leverage the filter() function in Notion formulas to extract specific data based on defined conditions! This comprehensive guide breaks down the structure of filter(), explains how it works, and provides practical examples. Learn to combine it with the lets() function for enhanced functionality and streamline your data management tasks in Notion.
cover image
Frame 5.png
1 more property

This is your sign to try filter()

In Notion Formula, filter() function allows users to extract specific items from a list based on defined conditions. In this blog post, we will explore the structure of the filter() function, break down how it works, and provide examples to illustrate its utility.
For this guide, I referenced the Notion Formula documentation and added my own examples and explanations.

Summary

Name
Syntax
Description
Example
filter()
filter(list, condition) or list.filter(condition)
Designed to return a list of values that meet certain criteria
filter([80, 150, 200], current > 100) → [150, 200]

filter() Formula

How filter() works

The filter() function iterates through each item in the provided list, checks it against the condition, and returns a new list that contains only those items that meet the specified criteria.
The syntax for the filter() function is as follows:
filter(list, condition)
Notion Formula
복사
Breaking it down
list: The collection of items that you want to filter through.
condition: The expression must evaluate to true for an item to be included in the resulting list. This condition should return a boolean value (either true or false).

Examples of filter()

Search
example
description
formula
results
Filtering a list containing number. - This will create a new sub-list that meets a specific number condition.
filter([80, 150, 200], current > 100) - Imagine you have a list of expenses. The condition applied is current > 100, filtering the list to include only expenses above $100. The resulting list contains those expenses that meet this criterion.
150,200
Filtering a list containing text. - This will create a new sub-list that meets a specific text condition.
filter(["Apple", "Avocado", "Cherry"], current.substring(0,1).equal("A")) - Let’s say you have a list of text. The condition extracts the first letter using .substring(0, 1) and checks if it is equal to “A” by .equal("A"). The resulting list will include only those items that meet this criterion.
Apple,Avocado
Filtering list containing dates - This will create a new sub-list that meets a specific date condition.
filter([parseDate("2023-01-01"), parseDate("2023-12-31"), parseDate("2022-05-15")], current > parseDate("2023-01-02")) - Let’s say you have a list of dates. The condition compares each date in the list against January 2, 2023, to check if it is greater than that date. The resulting list will include only those dates that meet this criterion.
@12/31/2023,@5/15/2024
Filtering list containing tags - This will create a new sub-list that meets a specific text condition.
filter(example tags, current.contains(1)) - In this example, we have a multi-select property called “example tags” with 4 tags [example1, example2, example3, example11] - The condition identifies tags that contain 1 and filters the tags that meet this condition. - Note that the resulting list is returned in text format (refer to our article in the section on Notion data types to see the types supported by Notion).
example1,example11
Filtering the list containing pages - This will generate a new sub-list that satisfies a specific condition based on the page or its property.
filter(prop("Tasks"), current.Status.contains("Done")) - Let’s say there’s a relation property named Tasks containing three items: [Item 1, Item 2, Item 3]. Each item has a status property called Status: - Item 1 with status Not Started - Item 2 with status In Progress - Item 3 with status Done The filter looks for the page with the Status Done, current.Status.contains("Done"), and filters the pages that meet this condition.

Conclusion

The filter() function is one of the most versatile and powerful formula functions in Notion. Try experimenting with the filter() function in your databases to fully unlock its potential!
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