Count Multi-Select Tags
Here’s a database that contains a multi-select property called Members. How can we get the number of members that have been added to each row?
length(replaceAll(prop("Members"), "[^,]", "")) + 1
/* Get the length of the string */
/* Convert the list of Members into a string of commas,
removing all other characters. */
"[^,]", // [^,] = every character EXCEPT `,`
) + 1 // Add 1, since the last item in the Members string has no comma
The Shares formula counts the number of members listed in the Members multi-select property for each heist.
Here’s how the formula works:
- 1.Pull the Members property into our formula. By default, multi-select property values are pulled in as a comma-separated string - e.g.
Danny, Rusty, Reuben, Linus.
- 2.We call the replaceAll function, which finds a pattern in a string and replaces it with another pattern. We write our function as
replaceAll(prop("Members"), "[^,]", ""):
- The first argument -
prop("Members")pulls in the Members property.
- The third argument -
""- replaces every found character with nothing, effectively removing them from the new string.
replaceAllfunction returns a string of commas - e.g.
- 4.We use the
length()function to count the characters in our string of commas - e.g.
- 5.Since the last item in the original list of Members won’t have a comma in it, we add
- 6.The formula outputs the final Shares count as a number. For the Bellagio Job, that number is
Here’s a new view of that database, which contains a new property called Split (Full). This formula efficiently combines the counting function we built above with the division operation, returning the share each heist member should get.
Here’s the code:
prop("Total") / (length(replaceAll(prop("Members"), "[^,]", "")) + 1)
prop("Total") / (
) + 1
My name is Thomas Frank, and I'm a Notion-certified writer, YouTuber, and template creator. I've been using Notion since 2018 to organize my personal life and to run my business and YouTube channel. In addition to this formula reference, I've created a free Notion course for beginners and several productivity-focused Notion templates. If you'd like to connect, follow me on Twitter.