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

...

D s
snippetBasic

Example:

CASE
d-codelang-syntax
RawWrangletrue
Typeref
showNotetrue
WrangleTextderive type:single value:
case([ Qty <= 10, 'low_qty', Qty >=100, 'high_qty', 'med_qty']) as:'Qty_Eval'

...

case([ Qty <= 10, 'low_qty', Qty >=100, 'high_qty', 'med_qty'])

Output: Returns a text string based on the evaluation of the Qty column:

  • Qty <= 10 : low_qty
  • Qty >= 100 : high_qty
  • All other values of Qty : med_qty

...

  • Test expressions are evaluated in the listed order.
  • Text expressions and results are paired values in an array.
  • You must include one or more test expressions.
  • Each test must include a result expression. Result expression can be a literal value or an expression that evaluates to a value of a supported data type.
  • If a quoted value is included as a test expression, it is evaluated as the value to write for all values that have not yet matched a test (else expression).
CASE
Code Block
D lang syntax
RawWrangletrue
Typesyntax
showNotetrue
WrangleTextcase([test1,
'result1',test2,
'result2',
testn,
'resultn','result_else'])

case([test1, 'result1',test2, 'result2', testn, 'resultn','result_else'])


ArgumentRequired?Data TypeDescription
test1, test2, testnYexpressionExpression that is evaluated. Must resolve to true or false
result1, result2, result2, result_elseYstringQuoted string that is written if the corresponding test expression evaluates to true.

...

To determine the day of the week, you can use the following transformtransformation:

d-

...

trans
RawWrangletrue
Typestep
WrangleTextderive type:single value:

...

weekday(Date)
p01NameFormula type
p01ValueSingle row formula
p02NameFormula
p02Valueweekday(Date)
SearchTermNew formula

You can build the discount rules into the following transform, which generates the Disc column:

d-

...

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

...

case([Qty<10, Std_Disc - 0.05, Qty>=20, Std_Disc + 0.05, weekday_Date == 5, Std_Disc + 0.02, Std_Disc]) as:'Disc'
p01NameFormula type
p01ValueSingle row formula
p02NameFormula
p02Valuecase([Qty<10, Std_Disc - 0.05, Qty>=20, Std_Disc + 0.05, weekday_Date == 5, Std_Disc + 0.02, Std_Disc])
p03NameNew column name
SearchTermNew formula

Results:

OrdDateCustIdQtyStd_DiscDisc
5/8/17C00140.050
5/9/17C002110.050.05
5/10/17C00340.050
5/11/17C001250.050.1
5/12/17C002190.050.07

...