Notion Answers

Help between Notion users

Register & Ask

It's free & easy

Get answers

Answers, votes & comments

Vote and select answers

Receive points, vote and give the solution



Trying to get the last two words from a rollup containing multiple commas in variable amounts. Need a formula that slice the string before the second last comma, and return everything after that. Currently googling regex trying to find the answer. If someone knows, please answer.

2 Answers


aloreols Points160

I had a similar problem. You can make the necessary tweaks to my code, if you find it useful.

As a bit of context, I had to slice a string made up of numbers separated by a hyphen, something like this: 2022-10-21. Basically, it's a date, although Notion won't recognize it as such. So, I created 3 formulas, each one to get the three parts of the string separately. I named these shorter strings "1st slice", "2nd slice", and so on.

The name of the string is prop("Name")
The first formula is: replaceAll(prop("Name"), "-.*", "")
The second formula is: replaceAll(if(length(prop("Name")) > length(prop("1st slice")), replaceAll(prop("Name"), concat(prop("1st slice") + "-"), ""), ""), "-.*", "")
The third formula is: if(length(prop("Name")) > length(prop("1st slice")), replaceAll(prop("Name"), concat(prop("1st slice") + "-" + prop("2nd slice") + "-"), ""), "")

After that, you just have to concatenate the strings you obtain. If you need any further help, I will be glad to help you.


viralsleep commented

Thanks for the solution. Ended up splitting the data into more than one row, and pulling the data using end().


polle commented

@viralsleep please add a new answer below with a formula example and select it. For sure it will help others with the same problem.


viralsleep commented

Will do so. However, the solution was simplifying the database itself, so that the complicated formula was no longer needed. Will post an explanation of that, with end result.


viralsleep Points170

Update on the solution to my question above.

As mentioned in a previous reply, realized was trying to solve a constructed problem. Had built a workspace for our team in Notion. In it am using a PARA structure (Projects, Areas, Resources, Archive). Using hierarchical databases to manage tasks from (Areas > Goals > Projects > Tasks > Todos > Time).

In the time database had sorted the data into two categories: Quarter and Month. The core database is Projects as that is where most things are defined, especially the time estimates. Was allowing project owner to select multiple time pages (i.e. multiple quarters or months).

This gave me multiple date ranges in the related column. So in order to calculate the deadline, estimated completion, was using trying to use end() to pick the last date. Obviously, this did not work as the data was a string() not a date().

That's when the question here was posed as was trying to extract the last date of the string which contained multiple date ranges.

Realized this was an overcomplicated solution, and ended up creating time templates consisting of Months, Quarters, and Halfs. Also restricting each project to only one of these. So by default, if the project is longer than 6 months, we split it up into multiple projects.

Not the technical solution expected to end up with, but was much faster to implement and actually works really well in practice.

Hope it helps someone else if they read this.

Please log in or register to answer this question.


Welcome to Notion Answers, where you can ask questions and receive answers from other members of the community.

Please share to grow the Notion Community!