Page tree


Contents:

   

This example demonstrates functions that can be used to evaluate the beginning and end of values of any type using patterns. 

Functions:

ItemDescription
STARTSWITH Function Returns true if the leftmost set of characters of a column of values matches a pattern. The source value can be any data type, and the pattern can be a Pattern , regular expression, or a string.
ENDSWITH Function Returns true if the rightmost set of characters of a column of values matches a pattern. The source value can be any data type, and the pattern can be a Pattern , regular expression, or a string.

Source:

The following inventory report indicates available quantities of product by product name. You need to verify that the product names are valid according to the following rules:

  • A product name must begin with a three-digit numeric brand identifier, followed by a dash.
  • A product name must end with a dash, followed by a six-digit numeric SKU.

Source data looks like the following, with the Validation column having no values in it.

InvDateProductNameQtyValidation
04/21/2017412-Widgets-01234523 
04/21/201704-Fidgets-12034166 
04/21/2017204-Midgets-442131 
04/21/2017593-Gidgets-40201224 

Transformation:

In this case, you must evaluate the ProductName column for two conditions. These conditional functions are the following:

IF(STARTSWITH(ProductName, `#{3}-`), 'Ok', 'Bad ProductName-Brand')


IF(ENDSWITH(ProductName, `-#{6}`), 'Ok', 'Bad ProductName-SKU')

One approach is  to create two new test columns and then edit the column based on the evaluation of these two columns. However, using the following, you can compress the evaluation into a single step without creating the intermediate columns:

Transformation Name Edit column with formula
Parameter: Columns Status
Parameter: Formula IF(STARTSWITH(ProductName, `#{3}-`), IF(ENDSWITH(ProductName, `-#{6}`), 'Ok', 'Bad ProductName-SKU'), 'Bad ProductName-Brand')

Results:

InvDateProductNameQtyValidation
04/21/2017412-Widgets-01234523Ok
04/21/201704-Fidgets-12034166Bad ProductName-Brand
04/21/2017204-Midgets-442131Bad ProductName-SKU
04/21/2017593-Gidgets-40201224Ok

See Also for EXAMPLE - STARTSWITH and ENDSWITH Functions:

This page has no comments.