
I have an excel which is having duplicate rows like in the screenshot. I need to convert this into data table and the all 4 values are combined into a single rows value.
How we can achieve this??

I have an excel which is having duplicate rows like in the screenshot. I need to convert this into data table and the all 4 values are combined into a single rows value.
How we can achieve this??
@agathiyanv please show output template as well
Hey @agathiyanv,
You can pivot the datatable to get the desired result as the linq pivot will use the Group By method. For reference have a look on the video.
Thanks,
Sanjit
ok wait please
Hey @agathiyanv,
Use the below liq code to get the desired result.
(From row In dt1.AsEnumerable
Group row By key = New With {
Key.name = row.Item("Name")} Into grp = Group
Select dt1Clone.LoadDataRow(New Object() {
key.name,
String.Join(",",grp.Select(Function(x)x("Address").ToString).ToArray)
}, True)).CopyToDataTable
where datClone would be the clone of the actual datatable, to get the same structure as dt1
Thanks,
Sanjit
Hi @agathiyanv
You can try this one, it will remove dublicate data according to particular column name
dt.AsEnumerable().GroupBy(Function(i) i.Field(Of String)(“ColumnName”)).Select(Function(g) g.First).CopyToDataTable()
Regards
@agathiyanv Use below code
(From row In dt1.AsEnumerable
Group row By key = New With {
Key.name = row.Item("Name")} Into grp = Group
Select dt1Clone.LoadDataRow(New Object() {
key.name,
String.Join(" ",grp.Select(Function(x)x("Address").ToString).ToArray)
}, True)).CopyToDataTable
can you show it with sample workflow?
how to remove the commas??
Hey @agathiyanv Replace the
String.Join(“,”,grp.Select(Function(x)x(“Address”).ToString).ToArray) with
String.Join(" ",grp.Select(Function(x)x(“Address”).ToString).ToArray)
Thanks,
Sanjit
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.