How To Extract List Items With A Notion Formula
What Is The Replace() Function?
Use replace() or replaceAll() to replace a character or set of characters in a string with a new value. You can also use this function to remove characters from a string all together.
The syntax: replace(prop(“Name of property with string“), “match character(s) in string“, “replace matched character(s) with this“)
replace(prop(“Name”), ““, ““) or replaceAll(prop(“Name”), ““, ““)
The replace() function replaces the first instance of matched character(s).
The replaceAll() function replaces all matched character(s).
Count List Items Formula
Count specified items in rollup, text, or multi-select properties. (ie. count items in rollup/multi-select property called High Impact).
The matched character below is Low Impact. Replace "Low Impact" with phrase you want to count.
A string property can be Text, Multi-Select, or a Rollup.
length(replaceAll(replaceAll(prop("String Property Name"), "Low Impact", "§"), "[^§]", ""))
Logic Behind The Solution
Replace all instances of matched character with a unique symbol.
length(replaceAll(replaceAll(prop("String Property Name"), "Low Impact", "§"), "[^§]", ""))
Replace all that is NOT the unique symbol with an empty space.
length(replaceAll(replaceAll(prop("String Property Name"), "Low Impact", "§"), "[^§]", ""))
Find the length of the unique symbols.
length(replaceAll(replaceAll(prop("String Property Name"), "Low Impact", "§"), "[^§]", ""))
Extract List Items Formula
Extract 1st, 2nd, 3rd, 4th, 5th ... last, ect. items in a list.
These formulas apply to lists separated by commas. Is your list separated by characters that aren't commas? Switch anywhere you see a comma with your special character.
0 = first item
1 = second item
2 = third item
Extract Item From List String
replaceAll(replace(prop("Name of Property"), "(?:[^,]*,){2}", ""), ",.*", "")
Extract Item From List String (Multi-Select or Text with extra space)
What is the difference between these formulas? The extra space will be removed after every comma and before every item. If your solution, for example, has a pesky extra space before the item, use this formula to remove the space.
This may only be necessary to use in some cases.
replaceAll(replace(prop("Name of Property"), "(?:[^,]*, ){2}", ""), ",.*", "")