Data360 Analyze

 View Only
Expand all | Collapse all

How to subtract current row int value to previous row int value?

  • 1.  How to subtract current row int value to previous row int value?

    Employee
    Posted 11-06-2020 04:50
    How to subtract current row int value to previous row int value?


  • 2.  RE: How to subtract current row int value to previous row int value?

    Employee
    Posted 11-07-2020 04:01

    You can use a script in the Transform node.

    You will need to store the current value as a variable so that it is available when the node processes the next record:

     

     

    ConfigureFields Script:

    ## Define a field to store the calculated value
    out1.result = int

    #Configure all fields from input 'in1' to be mapped
    #to the corresponding fields on the output 'out1'
    out1 += in1

    ProcessRecords Script:

    #Copy all fields from input 'in1' to the corresponding output fields
    #in output 'out1'. Copies the values of the fields that have been setup
    #in the mapping defined in the ConfigureFields property
    out1 += in1

    if node.firstExec:
        previousValue = 0

    ## If the current value is Null use 0 instead
    if in1.rand == Null:
        currentValue = 0
    else:
        currentValue = in1.rand

    ## Output the calculated value
    out1.result = previousValue - currentValue

    ## Store the current value for use with the next record
    previousValue = currentValue