Subtraction of two columns

Correct this-----------

filter_Status1.AsEnumerable().Select(Function(row) row.SetField(Of Double)(“(B-P) Amt”, If(IsNumeric(row(“Bal Amt”)) AndAlso IsNumeric(row(“Pat Amt”)), CDbl(row(“Bal Amt”)) - CDbl(row(“Pat Amt”)), 0))).CopyToDataTable()

i want Bal Amt-Pat Amt values into (B-P) Amt

The values like $80.00 and $0.00 in colums

same topic:

Hi @Arvind1

Try this

Code:

For Each row As DataRow In dt.Rows
    Dim amount1 As Double = 0
    Dim amount2 As Double = 0

    If Double.TryParse(row("Amount1").ToString().Replace("$", "").Replace(",", "").Trim(), amount1) = False Then
        amount1 = 0
    End If

    If Double.TryParse(row("Amount2").ToString().Replace("$", "").Replace(",", "").Trim(), amount2) = False Then
        amount2 = 0
    End If

    row("Difference") = amount1 - amount2
Next

Output:

image

Regards,

Hi @Arvind1 ,

Example in UiPath

  1. For Each Row in DataTable
    Activity: For Each Row
    DataTable: filter_Status1
  2. Inside the For Each Row Activity:
    First Assign Activity:
    To: row(“Bal Amt”)
    Value: row(“Bal Amt”).ToString().Replace(“$”, “”).Trim()
    Second Assign Activity:
    To: row(“Pat Amt”)
    Value: row(“Pat Amt”).ToString().Replace(“$”, “”).Trim()
    Third Assign Activity:
    To: row(“Bal Amt”)
    Value: If(IsNumeric(row(“Bal Amt”)), CDbl(row(“Bal Amt”)), 0)
    Fourth Assign Activity:
    To: row(“Pat Amt”)
    Value: If(IsNumeric(row(“Pat Amt”)), CDbl(row(“Pat Amt”)), 0)
    Fifth Assign Activity:
    To: row(“(B-P) Amt”)
    Value: CDbl(row(“Bal Amt”)) - CDbl(row(“Pat Amt”))

This approach ensures that:

Dollar signs and other non-numeric characters are removed from the Bal Amt and Pat Amt values.
The values are checked to ensure they are numeric before performing the subtraction.
The result of the subtraction is stored in the (B-P) Amt column.

Regards
Sandy

Not Work in my case, got an error in code

@Arvind1

Can you show us the error and workflow screenshot

Regards,

@lrtetala
i solve it with loop,
i receive an error some line to line error in invoke code activity
if you have a linq code for this please send

Thanks for support