<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" /> This example database created a roster for different missions. Each member in a pirate crew can mark whether or not they’re attending, and the Roster formula will output a list of those attending and not attending. The join()
function is used to create line breaks.
Created by Thomas Frank | Learn Notion Formulas | Notion Basics | Templates | Twitter
</aside>
// Compressed
join("\\n", (prop("Luffy") == true) ? "Luffy attending" : "Luffy not attending", (prop("Sanji") == true) ? "Sanji attending" : "Sanji not attending", (prop("Zoro") == true) ? "Zoro attending" : "Zoro not attending", (prop("Chopper") == true) ? "Chopper attending" : "Chopper not attending")
// Expanded
join(
"\\n",
(prop("Luffy") == true) ? "Luffy attending" : "Luffy not attending",
(prop("Sanji") == true) ? "Sanji attending" : "Sanji not attending",
(prop("Zoro") == true) ? "Zoro attending" : "Zoro not attending",
(prop("Chopper") == true) ? "Chopper attending" : "Chopper not attending"
)
<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" /> For fun, here’s another take on the Roster formula that uses replace and replaceAll - along with some advanced regular expressions - to create a single sentence that includes only the members who are attending (complete with commas):
</aside>
// Compressed
replace(replace(replace(replaceAll(join(", ", (prop("Luffy") == true) ? "Luffy" : "", (prop("Sanji") == true) ? "Sanji" : "", (prop("Zoro") == true) ? "Zoro" : "", (prop("Chopper") == true) ? "Chopper" : ""), "(^, | ,)", ""), "[,].$", ""), ",(?!.*,)", ", and"), "^([^,]*), and", "$1 and")
// Expanded
replace(
replace(
replace(
replaceAll(
join(
", ",
(prop("Luffy") == true) ? "Luffy" : "",
(prop("Sanji") == true) ? "Sanji" : "",
(prop("Zoro") == true) ? "Zoro" : "",
(prop("Chopper") == true) ? "Chopper" : ""
), "(^, | ,)", ""
), "[,].$", ""
), ",(?!.*,)", ", and"
), "^([^,]*), and", "$1 and"
)