I want to subtract two columns and automatically write the result in the “SALDO” column

I want to subtract two columns and automatically write the result in the “SALDO” column

Hi @dvojinovic
Try this
dt.AsEnumerable.ToList.ForEach(Sub(r)
r("Total")=CDec(r("Data1").ToString)-CDec(r("Data2").ToString)
End Sub
)
Input:

Output:

Cheers!!
You do the filter on last column remove where it has empty row and take rest in data table
Hi,
FYI, another approach:
We can use Expression property of DataColumn class as the following.
dt.Columns("Balance").Expression = "Convert(Column1, 'System.Double') - Convert(Column2, 'System.Double')"
Note: Please modify each column name to fit your table.
Sample
Sample20240509-1.zip (16.6 KB)
Regards,
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.