Slice

Slice functions let you extract a specified substring from a text value. This is a quick way of removing unwanted flags at the ends of a text value or mapping strings to shorter values.

Excel

  • =~LEFT!~(‹string›«, length»)

  • =~RIGHT!~(‹string›«, length»)

=LEFT(A1) // "Female" -> "F"
=RIGHT(A2,5) // "MAIN24601" -> "24601"

NB. If «length» is left blank, it returns the 1st digit only.

Tableau

  • ~LEFT!~(‹string›, ‹length›)

  • ~RIGHT!~(‹string›, ‹length›)

LEFT([Gender], 1) // "Female" -> "F"
RIGHT([Cost Code], 5) // "MAIN24601" -> "24601"

Alteryx

  • ~LEFT!~(‹string›, ‹length›)

  • ~RIGHT!~(‹string›, ‹length›)

LEFT([Gender], 1) // "Female" -> "F"
RIGHT([Cost Code], 5) // "MAIN24601" -> "24601"

OrgVue

The general format of splice in OrgVue is: ‹dimension›.value.~slice!~(‹start_index›«, end_index»)

  • Left: ‹dimension›.value.~slice!~(0, ‹end_index›)

  • Right: ‹dimension›.value.~slice!~(-‹start_index›)

node.gender.value.slice(0,1) // "Female" -> "F"
node.costcode.value.slice(-5) // "MAIN24601" -> "24601"

NB.:

  • The first character in a string has the index 0.

  • Negative numbers count from the end of the string.

  • If only 1 index is supplied, the default is to return all subsequent characters after that index, e.g.

    node.ordernumber.value.slice(3) // "NCF1066" -> "1066"

tSQL

  • ~LEFT!~(‹field›, ‹length›)

  • ~RIGHT!~(‹field›, ‹length›)

  • ~MID!~(‹field›, ‹start›«, length»)

SELECT LEFT(Gender, 1) AS GenderCode
FROM EmployeesData
-- "Female" -> "F"
SELECT RIGHT(CostCode, 5) AS CC 
FROM ProductsData
-- "MAIN24601" -> "24601"
SELECT MID(OrderNumber, 2, 4) AS OrderYear
FROM OrdersData
-- "UK2008ABP" -> "2008"

Python

The general splice format in Python is: ‹string›[«start_index»:«end_index»]

  • Left: ‹string›[:«end_index»]

  • Right: ‹string›[-«start_index»:]

gender[:1] # "Female" -> "F"
costCode[-5:] # "MAIN24601" -> "24601"

NB.:

  • The first character in a string has the index 0.

  • Negative numbers count from the end of the string.

  • If only the «start_index» is supplied and no : is included, the expression behaves like [:1] has been provided, e.g.:

orderNumber[3] # "NCF1066" -> "1"
  • The above examples assume variables have been declared for gender, costCode, and orderNumber. For more information, go to General > Variables.

Last updated

Was this helpful?