How to copy a column value into another new column in a datatable

Hi Team,

I need to copy one column value to another column in the same datatable

say fr ex: i have one datatable which contains Name, Address, Payment, Age

|ID| Code |Date |Amount |CR|
|1| BR |2022/02/22|10,000.00||
|2 |MK |2023/01/06|20,000.00||
|3| SH |2022/01/02|3,000.00||

I want to add Amount column values to CR column in a data table, please help

Hi @bhanu.priya2 ,

Use Read Range → store data un Dt1

for each row in data table —>dt1

body

assign currentrow(“CR”) = Currentrow(“Amount”).

after the loop use

Write Range Workbook on same sheet

Regards
Sandy

i want to store in datatable

When u are looping for each row in datatable it will be stored automatically in Dt1 , even u need not write in to excel too using write range

Hi @bhanu.priya2

Try this

For Each row As DataRow In dt.Rows
    ' Copy the value from the Amount column to the CR column
    row("CR") = row("Amount")
Next

Regards,

hi @bhanu.priya2 ,
You can try that


Regards,

Hi @bhanu.priya2

We can use the linq expression for the expected output, check the below steps,
→ Use the read range workbook activity to read the excel and store in a datatable called dt.
→ Use the assign activity to write the below linq expression, create a variable called Output_dt which is datatable datatype variable,

- Assign -> Output_dt = (From row in dt.asenumerable()
Let CR = row("Amount").toString
Select dt.Clone.rows.add({row("ID"),row("Code"),row("Date"),row("Amount"), Cdbl(CR)})
     ).Copytodatatable()

→ Then use the write range workbook activity to write the Output_dt to the same excel.

Check the below workflow for better understanding,
Sequence5.xaml (8.9 KB)

Input -
image

Output -
image

Hope it helps!!

@bhanu.priya2

Use the code below to copy the value from one column to another

dt.AsEnumerable().ToList().ForEach(Sub(row) row("CR") = row("Amount"))