4 Replies Latest reply on Feb 12, 2014 10:28 AM by Amy Cronin

# Is there a formula that would switch Last Name First Name to First Name Last Name?

Rather than constantly asking my dba to create views with names listed the way I want, I'd like to be able to use a calculation to change the very common instances of names fields that are either "Lastname, Firstname" or "Lastname Firstname" to display first name first.

• ###### 1. Re: Is there a formula that would switch Last Name First Name to First Name Last Name?

I'm not sure about the formula; but you can try renaming these column names in Tableau itself. Right CLick -> Rename!

Hope it helps!

• ###### 2. Re: Is there a formula that would switch Last Name First Name to First Name Last Name?

The problem is that both names are in one field.

• ###### 3. Re: Is there a formula that would switch Last Name First Name to First Name Last Name?

Hi Amy I had created a packaged workbook to help you with this, but it doesn't appear that I can attach to this forums, so I will do my best to explain.

First you will want to find the position in the string of the comma/space in the name field so that you can tell the function where to start you're selection (See below):

Position of Comma

FIND([Name], "," )

Position of Space

FIND([Name], " " )

Next you need to create a calculation that selects the string values and then concatenates them in the correct order. I added them to an IF statement to say if there is a comma, then use the position of comma calc, otherwise use the position of space calc.

Proper Name Formatting

If CONTAINS([Name], "," )

then str(LTRIM(mid([Name], [Position of Comma] +1 ) ))+SPACE(1)+str(LTRIM(left([Name], [Position of Comma] -1 )))

else str(LTRIM(mid([Name], [Position of Space] +1 ) ))+SPACE(1)+str(LTRIM(left([Name], [Position of Space] -1 )))

end

All you should have to do is swap in your field name where I have [Name] in the above calculations and you should be good to go.

Hope this helps.

1 of 1 people found this helpful
• ###### 4. Re: Is there a formula that would switch Last Name First Name to First Name Last Name?

Thank you so much!!! That is easily the best explanation of those kooky string formulas that I've seen. Really appreciate it.