People Goal 1 - Part 8: Add a Full Name calculation

Document created by Kedar on Jan 26, 2015Last modified by communitymanager on May 12, 2015
Version 13Show Document
  • View in full screen mode

 


Another useful calculation would be a Full Name field, combining the Last Name and First Name, separated by a comma and space.

 

If you had to create a Full Name text field rather than First Name and Last Name, don’t do the steps in this section, though we recommend you read it through anyway.


Goal:

 

Create a Full Name calculation field derived from the Last Name and First Name fields.



Steps:

 

  1. For Field Name, enter Full Name.

  2. Choose “Calculation” from the Type list.

  3. Click the Create button.

    A Specify Calculation dialog window appears.

  4. In the formula entry area, enter the following expression:  Last Name  & ", " & First Name

    When you include the ampersand as an operator in your expressions, FileMaker Pro understands that you want to join together pieces of text (also called strings). The technical term for joining together pieces of text is concatenation.

    Here you are joining together the contents of the Last Name field with a comma and space, and then joining that to the contents of the First Name field.

  5. Make sure that the Calculation result in the lower left of the dialog box has the value “Text”.

    Whenever you create a calculation field, you want to doublecheck that it is set up to return the type of data you want. When an inappropriate data type is chosen (in this case "Number" instead of "Text"), you might get unexpected behavior later on.

  6. Click the OK button to dismiss the dialog and create the field.

 

 

Improving this Calculation Field


Right now, if either the First Name or Last Name field is empty, the result of the Full Name calculation ends up with a leading or trailing comma, which looks a little strange:

 

Last Name = Jones

First Name =

Full Name = Jones,

 

Last Name =

First Name = Cindy

Full Name = , Cindy


 

One possibility for improving the result is this:

 

Last Name = Jones

First Name =

Full Name = Jones, (unknown)

 

Last Name =

First Name = Cindy

Full Name = (unknown), Cindy


 

To get this result, change the expression for the “Full Name” calculation to the following:

 

If( IsEmpty(Last Name); "(unknown)" ; Last Name ) & ", " & If( IsEmpty(First Name); "(unknown)" ; First Name )

 

 

This expression introduces two more concepts:

 

  • The IsEmpty(field) function

    This returns the logical value True if the field is empty, otherwise it returns False.

  • The If (test ; result1 ; result2)  function

    The “If” function makes a choice about what result to return, based on the logical expression ‘test’. Basically, it says:  “If the expression ‘test’ is true, then return result1, otherwise return result2.”



This is the decision-making process in the expression:


  • If the Last Name field is empty, return “(unknown)” — otherwise return the contents of the field.

  • Then add a comma and a space to the end of that.

  • Then add this as well:  If the First Name field is empty, return “(unknown)” — otherwise return the contents of that field.

      

      

Attachments

    Outcomes