Add decremental values in a data table

I have a Data Table with “Row No” column, I want to add a new column with decremental values of this pattern:
The image shows a spreadsheet with three columns, D (Row No), E (New Row No), and F, with F representing the difference between columns D and E. (Captioned by AI)

How can I do it with invoke code?
or any other way.
Thanks

Hi,

How about the following?

image

dt.Columns.Add("Diff",GetType(Object))
dt.AsEnumerable.Where(Function(r) Int32.TryParse(r("New Row No").ToString,New Int32)).ToList.ForEach(Sub(r)
    r("Diff") = CInt(r("RowNo").ToString)-CInt(r("New Row No").ToString)
End Sub
)

Sample
Sample20240913-1.zip (9.4 KB)

Regards,

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.