Working with Data: All the calculations you need t
  • Introduction
  • What is this book?
  • How to Use this Book
  • Document Notes
  • Authors' Thanks
  • Strings
    • Concatenate
    • Split
    • Length
    • Slice
    • Trim
    • Contains
    • Match
    • Replace
    • Upper/Lower Case
  • Numbers
    • Sum
    • Average
    • Roll Ups
    • Round
    • Floor
    • Power
    • Square Root
    • Absolute
  • Dates
    • Date Difference
    • Age
  • Logical
    • Logical Operators
    • If
    • Case / Switch
    • Is Null/Empty
  • General
    • Count
    • Filter
    • Sort
    • Lookup/Join
    • Variables
    • Convert Type
  • Appendix
    • DateTime Parts
    • Helpful Resources
Powered by GitBook
On this page
  • Excel
  • Tableau
  • Alteryx
  • OrgVue
  • tSQL
  • Python

Was this helpful?

  1. Strings

Trim

PreviousSliceNextContains

Last updated 5 years ago

Was this helpful?

Values sometimes have spaces at the start or end because of mistakes in data entry or the use of a split operation to break apart a CSV (comma separated list). These aren't always easily visible but can cause problems if you're trying to do exact matches for a . Trim allows you to strip out trailing or leading characters (usually white space by default) to clean up your text field.

Excel

=~TRIM!~(‹string›)

=TRIM(A1) // " Recruiter " -> "Recruiter"

Tableau

Tableau supports three TRIM() operations:

  • ~TRIM!~(‹string›) removes leading and trailing spaces

  • ~LTRIM!~(‹string›) removes leading spaces only

  • ~RTRIM!~(‹string›) removes trailing spaces only

TRIM([Job Role]) // " Recruiter " -> "Recruiter"
LTRIM([Job Role]) // " Recruiter " -> "Recruiter "
RTRIM([Job Role]) // " Recruiter " -> " Recruiter"

Alteryx

Alteryx supports three TRIM() operations:

  • ~TRIM!~(‹within_string›«, target_string») removes leading and trailing characters

  • ~TRIMLEFT!~(‹within_string›«, target_string») removes leading characters only

  • ~TRIMRIGHT!~(‹within_string›«, target_string») removes trailing characters only

TRIM([Job Role]) // " Recruiter " -> "Recruiter"
TRIMLEFT([Job Role]) // " Recruiter " -> "Recruiter "
TRIMRIGHT([Job Role]) // " Recruiter " -> " Recruiter"

NB. If «target_string» is excluded, the default behaviour is to trim whitespace. If it is included, you can specify what character to trim:

TRIM([Job Coded], "*") // "**HR014**" -> "HR014"

OrgVue

Gizmo does not support Trim operations, although OrgVue workspace will usually trim strings by default.

tSQL

  • ~LTRIM!~(‹string›) removes leading spaces only

  • ~RTRIM!~(‹string›) removes trailing spaces only

  • To remove leading and trailing spaces, use ~RTRIM!~(~LTRIM!~(‹string›))

SELECT LTRIM(JobRole) AS JobRole
FROM EmployeesData
-- " Recruiter " -> "Recruiter "
SELECT RTRIM(JobRole) AS JobRole
FROM EmployeesData
-- " Recruiter " -> " Recruiter"
SELECT RTRIM(LTRIM(JobRole)) AS JobRole
FROM EmployeesData
-- " Recruiter " -> "Recruiter"

Python

‹string›.~strip(«target_string»)!~

jobRole.strip() # " Recruiter " -> "Recruiter"
# OR
jobCode.strip('*') # " HR014**" -> " HR014"

NB.

  • If «target_string» is excluded, the default behaviour is to trim whitespace.

  • If «target_string» is included, you can specify what character to trim.

The above examples assume variables have been declared for jobRole and jobCode. For more information, go to .

Lookup/Join
General > Variables