Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

D toc
Excerpt

Returns the least common multiple shared by the first and second arguments.

  • 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

D code

derive type:single value: LCM(10,4) as:'twenty'

Output: The least common multiple between values 10 and 2 is 20 and is stored in a new column called twenty

D s
snippetSyntax

D code

derive type:single value: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.

D s lang notes

value1, value2

Integer expressions, column references or literals to multiply together.

  • Missing or mismatched values generate missing string results. 

D s
snippetusage

Required?Data TypeExample Value
YesLiteral, function, or column reference returning an Integer value15


D s
snippetExamples

Example - Basic LCM function

Source:

stringrepeat_count
ha0
ha1
ha1.5
ha2
ha-2


Transform:

D code

derive type:single value: repeat(string, repeat_count) as: 'repeat_string'


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:

prodNameprodId
w011
w0210000001
w03345
w0410402

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 drop the intermediate columns and rename column2 to prodId, you have the following table:

prodNameprodId
w0100000001
w0210000001
w0300000345
w0400010402


D s also
labelmath