Best practice

Advanced text cleansing

For everyday cleansing, such as trimming spaces, changing case and removing punctuation, use the Text Cleanse operation. The techniques below combine Calculate and Regex for jobs it doesn’t cover.

Add leading zeros before a number

For example, format a ‘Row Number’ column from 1, 2, 3, 4 to 00001, 00002, 00003, 00004. Use the following formula in Calculate:

RIGHT(CONCATENATE("00000", 'Row Number'), 5)

CONCATENATE puts five zeros in front of the number, and RIGHT keeps the last five characters. Change both the number of zeros and the 5 to set a different length.

Cleanse and split names of people

Scenario: you have names of people in a single column. The names need to be cleansed to remove Mr, Mrs, etc and split into two columns of Last Name and First Name.

Contact support@quantemplate.com to have a copy of these steps placed into a pipeline in your organisation.

Input data

Spreadsheet with a single Name column holding names such as ‘Mr Joe Gargery III’, ‘Mrs. Johanna Smith’, ‘Dr. Barnabas Herbert Pumblechook’, ‘Leonardo da Vinci’ and ‘Ursula von der Leyen’, mixing titles, suffixes and multi-word last names

Output data

Quantemplate output with First names and Last name columns in upper case, without titles or suffixes: for example JOE and GARGERY, JAMES LEE and JOHNSON, LEONARDO and DA VINCI, URSULA and VON DER LEYEN

Steps

The stage uses five operations:

Operations list for the stage: Remove Prefixes, Suffixes and Clean up last name are Calculate operations, Extract first names and Extract last name are Regex operations, and Remove unwanted columns is Map Column Headers
  1. Insert a Calculate operation to remove prefixes and suffixes.
  2. Uppercase the names. This reduces the number of permutations required to remove suffixes etc. You could keep it mixed case if required and add the additional permutations:
    UPPER('Name')
  3. Remove dots from Mr. Jr. etc:
    SUBSTITUTE('Name',".","")
  4. Remove common prefixes and suffixes (Mr, Dr, Sr, III, etc):
    IF(LEFT('Name',3)="MR " or LEFT('Name',3)="DR " or LEFT('Name',3)="MS ", RIGHT('Name', LENGTH('Name')-3), 'Name')
    IF(LEFT('Name',4)="MRS ", RIGHT('Name', LENGTH('Name')-4), 'Name')
  5. Last names comprising multiple words separated by a space are typically ‘van’, ‘von der’, ‘de’, etc. To deal with them, we identify the types individually and substitute the space with a ‘#’ character. This allows us to treat the last name as a single word. The # is removed later:
    SUBSTITUTE('Name',"VON DER ", "VON#DER#")
  6. Extract first names using a Regex operation, taking the first group:
    (.*) ([^ ]+)$
  7. Extract the last name using the same Regex, taking the second group.
  8. Clean up the last name with a Calculate operation to remove the # character:
    SUBSTITUTE('Last name',"#"," ")
  9. Finally, clean up the columns. Remove the unwanted ‘Name’ column using Map Column Headers. This could be done as part of a more general column clean-up or mapping to output schema later in the pipeline if you wished.