How multiple with - 1 or - to a column in a datatable?

I use generate data table activity to collect data into table form. And Now in the last column of the table, I want to add a Negative Sign to it.

Thanks

Hi @sunilkanth

  1. do for each row in datatable(dt)

  2. Inside it do either of these

a) If the column type is double then
Use Assign
currentrow(dt.Columns.Count-1) = Cdbl(currentrow(dt.Columns.Count-1).ToString)*(-1)
b) If the column type is string then
Use Assign
currentrow(dt.Columns.Count-1) = (Cdbl(currentrow(dt.Columns.Count-1).ToString)*(-1)).ToString

cheers

Can you pls explain the Query?

Also I tried this

CurrentRow(“Column5”.Count-1)=Cdbl(CurrentRow(“Column5”.Count-1).ToString)*(-1)

and I got the following error
Assign: Cannot find Column 6.

My Column Names are ‘Column2’,Column4’,Column5 respectively.

If you just want to convert the numbers to negative numbers…

For Each Row in Datatable

  • Assign CurrentRow(“ColumnName”) = 0 - CDbl(CurrentRow(“ColumnName”).ToString)

This assumes the column is a double datatype. If the column is string then your expression would be…

(0 - CDbl(CurrentRow(“ColumnName”).ToString)).ToString

Hi @sunilkanth

I am multiplying the value in the column with -1 so that it will be negative

And as you said it is the last column…what i did is instead of gving the column name or number i counted how many columns are there and subtracted 1 to give the last column index as index starts from 0 .

Dt.columns.count will give the count of columns.

If you want to give column name instead then you have to give like this

CurrentRow("Column5")=Cdbl(CurrentRow("Column5").ToString)*(-1)

Cheers