Help

Re: Formula to Extract Last Name from Full Name

Solved
Jump to Solution
3078 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Cole_Wedemeier
6 - Interface Innovator
6 - Interface Innovator

Hello!

I know at one time there were several threads that spoke to extracting the First Name from a full name, and also a formula for extracting the Last Name. While I can find several threads with the code for First Name, I cannot find any that show for Last Name now that I'm in need of it 😂

First Name Formula Found: 

IF(FIND(" ",{Full Name})=0, {Full Name}, LEFT({Full Name}, FIND(" ",{Full Name})-1))

I've tried different variations using RIGHT instead of left, but I either get really odd returns where some last names are extracted properly, and others are completely way off, or I get blank returns. 

I have several Full Names that include more than 1 name as that Last Name. Example: Olivia Gutierrez Lawson. I would need "Gutierrez Lawson" to appear in the last name field with the formula. 

I feel confident in some of my formula creation skills and then there are times like this when I realize just how little I know haha. I am so grateful there is a community of people who are way better at understanding formulas than I am that I can ask for help from.

1 Solution

Accepted Solutions
Steve_Haysom
8 - Airtable Astronomer
8 - Airtable Astronomer

try this: 

First name: REGEX_EXTRACT(Name, "^[^ ]+")
 
Last name: REPLACE(Name, 1, LEN({First name}) + 1, "")

Untitled.png

See Solution in Thread

8 Replies 8
Ron_Daniel
7 - App Architect
7 - App Architect

One of the issues you'll run into with extraction is that there is no way to differentiate whether a space is in the first name ("Mary Ann") or the last name ("Gutierrez Lawson"). Is it possible to use separate fields for first and last names and then concatenate them when you need the full name?

@Ron_Daniel that is the typical way I setup every table, however, someone set this one up and I'm trying to make it work without having to do a ton of manual work now afterwards 🙃

I'm willing to risk the first name being split up as I recognized that as a potential issue too. 

Ron_Daniel
7 - App Architect
7 - App Architect

Ah, inheritance!
Well, it's less than ideal, but you can make it work (mostly) like this:
Screen Shot 2023-01-18 at 2.16.50 PM.png

First Name formula is

IF(FIND(" ",{Full Name})=0, {Full Name}, LEFT({Full Name}, FIND(" ",{Full Name})-1)) 
Last Name formula is
REPLACE({Full Name},1,FIND("~",SUBSTITUTE({Full Name}," ","~",LEN({Full Name}) - LEN(SUBSTITUTE({Full Name}," ","")))),"")
Steve_Haysom
8 - Airtable Astronomer
8 - Airtable Astronomer

try this: 

First name: REGEX_EXTRACT(Name, "^[^ ]+")
 
Last name: REPLACE(Name, 1, LEN({First name}) + 1, "")

Untitled.png

Ron_Daniel
7 - App Architect
7 - App Architect

@Steve_Haysom 's solution is shorter, more elegant, and produces better results. Win!

thanks Ron! :@)

@Steve_Haysom THANK YOU! That works like a dream and I would have NEVER come up with that myself. 

Much appreciate to you as well, @Ron_Daniel!

Ron_Daniel
7 - App Architect
7 - App Architect

@Cole_Wedemeier  - this has prompted me to finally focus on learning regular expressions (REGEX). They're super-powerful for all of us to have in our formula toolbox!