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

...

  • Each argument can be a literal Integer number, a function returning an Integer, or a reference to a column containing Integer values.

D s
snippetBasic

LCM
d-codelang-syntax
RawWrangletrue
Typeref
showNotetrue
WrangleTextderive type:single value:
lcm(10,4) as:'twenty'

lcm(10,4)

Output: The  Returns the least common multiple between values 10 and 2 is 20 and is stored in a new column called twenty4, which is 20

D s
snippetSyntax

LCM
d-code-lang-syntax
RawWrangletrue
Typesyntax
showNotetrue
WrangleTextderive type:single value:
lcm(value1, value2)

lcm(value1, value2)


ArgumentRequired?Data TypeDescription
value1YstringThe first value must be an Integer literal, column reference, or expression that evaluates to an Integer value.
value2YstringThe first value must be an Integer literal, column reference, or expression that evaluates to an Integer value.

...

stringrepeat_count
ha0
ha1
ha1.5
ha2
ha-2


TransformTransformation:

d-

...

trans
RawWrangletrue
p03Value'repeat_string'
Typestep
WrangleTextderive type:single value: repeat(string, repeat_count) as: 'repeat_string'
p01NameFormula type
p01ValueSingle row formula
p02NameFormula
p02Valuerepeat(string, repeat_count)
p03NameNew column name
SearchTermNew formula

Results:

stringrepeat_countrepeat_string
ha0 
ha1ha
ha1.5 
ha2haha
ha-2 

Example - Padding values

In the following example, the imported prodId values are supposed to be eight characters in length. Somewhere during the process, however, leading 0 characters were truncated. The steps below allow you to re-insert the leading characters.

Source:

...

Transform:

First, we need to identify how many zeroes need to be inserted for each prodId:

D code

derive type:single value: 8 - len(prodId) as: 'len_prodId'

Use the REPEAT function to generate a pad string based on the above values:

D code

derive type:single value: repeat('0', len_prodId) as: 'padString'

Merge the pad string and the original prodId column:

D code

merge col: padString,prodId as: 'column2'

Results:

When you delete the intermediate columns and rename column2 to prodId, you have the following table:

00010402
prodNameprodId
w0100000001
w0210000001
w0300000345
w04


D s also
labelmath