Hi,
in my database (table) I have the field Name (type is Single line text), where every row of my table contains the full name and format like this:
John Norton
Evelyn Baker
Peter Smith
…
So it is Name and Surname. Sometimes (rarely) it may be also like this (with middle name):
John William Norton
Evelyn C. Baker
…
If I want to sort it by Surname, itš not possible, it is always sorted by first name.
Is there any workaroud how can I achieve the sorting by surname (which means second, or better last word - if the middle name is present - from the field)?
I can even imagine that there could be a small update of Baserow product where an ew type of field (it could be called Name type) is introduced and there could be an additional “Sort by last word” checkbox when editing this type of field.
This is possible with the following formula: right(field('Name'),length(field('Name')) - search(field('Name'),' '))
The formula returns the right part of the text after the first space in the field ‘Name’. For example:
John Norton → Norton
Evelyn Baker → Baker
Peter Smith → Smith
If you have a middle name, you need to add an extra field with the same formula. Except that you now refer to your previous formula field. This will repeat the same operation and search for a new space in the text: right(field('Formula'),length(field('Formula')) - search(field('Formula'),' '))
Hi Frederik, thanks a lot for the solution! I will try it.
That means if I have the name mixed (some with while others without middle name), then I should use the Formula 2 method (field) to sort my table, but I also need have the Formula field set-up, even that it can be hidden, right. without Formula field it would not work (sort) correctly. Am I correct?
Correct, you always sort the table on the field Formula2. But you need to have the field Formula because the result of this field is used to calculate the final result in Formula2.
I did not rename the fields to set up a small demo, but I suggest you rename the fields in your table:
Hi @frederikdc ! Could you please help me create a similar formula, but now generating (extracting) the first name from my “Name” field, which is a simple text field that usually contains two words (first name and surname), sometimes three (first name, middle name and surname)?
Thank you!
Thank, it work.
But I see one difference ifcomparing to this formula (which extracts Surname from the Name field): right(field('Name'),length(field('Name')) - search(field('Name'),' '))
If I click the field where the First Name is generated by formula and press CTRL+C and later I do paste, teher are quotes added before and after the copied content. If I do copy/paste the Surname (generated by the formula, see above), it works correctly and no quotes are added.
Try simple pasting the copied value from that new formula field to let’s say Notepad or anywhere. It always results in: "Firstname "
So quotes added from left and right and space added before right quote.
Formula field is fetching the content from my Name field, which is the first field in my table and is Single line text.
Btw. another, more complicated scenario:
If I have some names just First and Surname, some other Firstname and Middlename and Surname.
Then, some of both types have also (but not all!) a university degree after the name, separated by comma AND space, some of them have even two titles f.e.: “Peter Smith, MBA” or “Dan A. Foster, Ph.D., FEBO”
How will I remove the comma? Now it is interpreted by the formula in such a way, that the limiter is space, so the comma is supposed to be a part of the surname. And also, I would like to create another formula field (or two fields, if more titles are present), which would recognize the comma and used the text after this comma (removing a space first) and until next comma (which would be a limiter).
Hope that I explained it clearly.
Please, is there any guide, how to build the correct formula structure (syntax)? Would like to learn to work with it.
Right now I just don’t understand, where and in which way should I use the regex_replace function.
Thanks.