Hi Guys,
I have a datatable as below -
And I want the datatable to look like this -
That is suffix with ‘000000’, ‘100000’, ‘200000’, ‘300000’, and then repeat again with same (should stop at 300000 and start next with 000000).
(Every row has 4 row items that are equal then a new one starts for four rows and then again,
e.g.
911251
911251
911251
911251
811511
811511
811511
811511)
Hi @shikharno.7
You can use the simple LINQ Expression to achieve the expected output,
Follow the process,
→ Store the datatable in a variable called dt_Input.
→ Use the assign activity to write the below LINQ Expression,
- Assign -> dt_Output = (From row In dt_Input.AsEnumerable().Select(Function(r, i) New With {Key .Row = r, Key .Index = i})
Select dt_Input.Clone.LoadDataRow(New Object() {
row.Row(0).ToString() & ((row.Index Mod 4) * 100000).ToString("D6"),
row.Row(1),
row.Row(2)
}, False)).CopyToDataTable()
→ dt_Output is a datatable variable which stores the output data.
Hope it helps!!
Yoichi
(Yoichi)
May 22, 2024, 11:27am
3
Hi,
FYI, another approach using InvokeCode
dt.AsEnumerable.ToList.ForEach(Sub(r)
r("ABC")=r("ABC").ToString+((dt.Rows.IndexOf(r) Mod 4)*100000).ToString("d6")
End Sub)
Sample
Sample20240522-2a.zip (3.4 KB)
Regards,
1 Like
system
(system)
Closed
May 25, 2024, 11:27am
4
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.