Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space DEV and version next

...

Column reference example:

LEN
d-codelang-syntax
RawWrangletrue
Typeref
showNotetrue
WrangleTextderive type:single value:
len(MyName)

len(MyName)

Output:

...

Returns the number of characters in the value in column MyName

...

.

String literal example:

LEN
d-codelang-syntax
RawWrangletrue
Typeref
showNotetrue
WrangleTextderive type:single value:
len('Hello, World')

len('Hello, World')

Output:

...

Returns the value 12

...

.

D s
snippetSyntax

LEN
d-codelang-syntax
RawWrangletrue
Typesyntax
showNotetrue
WrangleTextderive type:single value:
len(column_string)

len(column_string)


ArgumentRequired?Data TypeDescription
column_stringYstringName of the column or string literal to be applied to the function

...

ProductNameProductIdErrProductName
Chocolate Bunnie123456Error-ProductName
Chocolate Squirl88442286Error-ProductName
Chocolate Gopher12345 

TransformTransformation:

To validate the length of the values in ProductId, enter the following transform. Note that the as parameter enables you to rename the column as part of the transform.

d-

...

trans
RawWrangletrue
p03Value'ErrProductIdLength'
Typestep
WrangleTextderive type:single value:

...

if(

...

len(ProductId) <> 6, 'Error-length-ProductId','') '' as: 'ErrProductIdLength'
p01NameFormula type
p01ValueSingle row formula
p02NameFormula
p02Valueif(len(ProductId) <> 6, 'Error-length-ProductId','')
p03NameNew column name
SearchTermNew formula

The dataset now looks like the following:

...

You can blend the two error columns into a single DataValidationErrors error column using the following merge transform. Note again the use of the as parameter:

d-

...

trans
RawWrangletrue
p03Value'DataValidationErrors'
Typestep
WrangleTextmerge col:ErrProductName,ErrProductIdlength with:' ' as:'DataValidationErrors'
p01NameColumns
p01ValueErrProductName,ErrProductIdlength
p02NameSeparator
p02Value''
p03NameNew column name
SearchTermMerge columns

To clean up the data, you might want to do the following, which trims out the whitespace in the DataValidationErrors column and removes the two individual error columns:

d-

...

trans
RawWrangletrue
Typestep
WrangleTextset col:DataValidationErrors value:

...

trim(DataValidationErrors)
p01NameColumns
p01ValueDataValidationErrors
p02NameFormula
p02Valuetrim(DataValidationErrors)
SearchTermEdit column with formula

d-

...

trans
RawWrangletrue
Typestep
WrangleTextdrop col:ErrProductName,ErrProductIdLength

D code

drop col:ErrProductIdLength

p01NameColumns
p01ValueErrProductName,ErrProductIdLength
p02NameAction
p02ValueDelete selected columns
SearchTermDelete columns

Results:

The final dataset should look like the following:

...