<aside> <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/a5a1e3ce-00fa-46e4-9a75-58c2aed9e8ce/Notion_Fundamentals_with_Thomas_Frank_-_Avatar_2021.png" alt="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/a5a1e3ce-00fa-46e4-9a75-58c2aed9e8ce/Notion_Fundamentals_with_Thomas_Frank_-_Avatar_2021.png" width="40px" /> 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?

We can accomplish this by using the replaceAll function, as shown in the Shares formula:

Created by Thomas Frank | Learn Notion Formulas | Notion Basics | Templates | Twitter

</aside>

Heist Shares

// Compressed
length(replaceAll(prop("Members"), "[^,]", "")) + 1

// Expanded

/* Get the length of the string */

length(

	/* Convert the list of Members into a string of commas, 
	removing all other characters. */

  replaceAll(
    prop("Members"),
    "[^,]", // [^,] = every character EXCEPT `,`
    ""
  )
) + 1 // Add 1, since the last item in the Members string has no comma

Splitting a Pool of Money

<aside> <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/a5a1e3ce-00fa-46e4-9a75-58c2aed9e8ce/Notion_Fundamentals_with_Thomas_Frank_-_Avatar_2021.png" alt="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/a5a1e3ce-00fa-46e4-9a75-58c2aed9e8ce/Notion_Fundamentals_with_Thomas_Frank_-_Avatar_2021.png" width="40px" /> In the divide (/) example, this Heist Splitter example was used to show how we could split a Total pool of money among the members who took part in each heist.

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.

</aside>

Split (Full) Formula

// Compressed
prop("Total") / (length(replaceAll(prop("Members"), "[^,]", "")) + 1)

// Expanded
prop("Total") / (  
	length(
    replaceAll(
      prop("Members"),
      "[^,]",
      ""
    )
  ) + 1 
)

© Thomas Frank