How to merge multiple columns to single column

Hi,
How to merge multiple columns to single column
e.g. I want to merge column 3,4,5, 6 untill there is data in that row,
columns might vary , it can be 10 or 20 or 21
but not necessarily data will be in all columns
but merge output should be in column 3, amd merge include 3 onwards .

Hi @1a2bc346dgjk7544ebjkkbvf

Check out this video link

1 Like

Hello @1a2bc346dgjk7544ebjkkbvf

Assign activity:
To: dt
Value: (From row In dt.AsEnumerable()
Let mergedValue = String.Join(β€œβ€, row.ItemArray.Skip(2).Select(Function(item) item.ToString()))
Select dt.Rows.Add(mergedValue)).CopyToDataTable()

Thanks & Cheers!!!

Hi @1a2bc346dgjk7544ebjkkbvf

Try this

Code:

DT.AsEnumerable().ToList().ForEach(Sub(row)
    Dim mergedData = row.ItemArray.Skip(2).
        Where(Function(item) Not String.IsNullOrWhiteSpace(item.ToString())).
        Select(Function(item) item.ToString()).
        Aggregate(Function(current, nextItem) current & ", " & nextItem)
    row(2) = mergedData
End Sub)

Please find the below xaml for your reference

BlankProcess12.zip (46.8 KB)

Hope this helps!!

1 Like

Hi @1a2bc346dgjk7544ebjkkbvf

Use this Linq Query

inputDT.AsEnumerable().ToList().ForEach(Sub(row)
row.SetField(β€œD”, row(β€œA”).ToString() & row(β€œB”).ToString() & row(β€œC”).ToString()))

Cheers…!

This is working perfectly ! Thanks !!
@lrtetala

Please help me with the code if I want to merge specific col to specific col.

e.g. column 3 to 6 like this . output of merged should be in column 3.

1 Like

Hi @1a2bc346dgjk7544ebjkkbvf

Try this:

DT.AsEnumerable().ToList().ForEach(Sub(row)
    Dim columnsToMerge = Enumerable.Range(3, 4)
    Dim mergedData = columnsToMerge.
        Select(Function(col) row(col).ToString()).
        Where(Function(item) Not String.IsNullOrWhiteSpace(item)).
        Aggregate(Function(current, nextItem) current & ", " & nextItem)
    row(2) = mergedData
End Sub)
1 Like

Hi @1a2bc346dgjk7544ebjkkbvf

Try this

Code:

DT.AsEnumerable().ToList().ForEach(Sub(row)
    Dim mergedData = String.Join(", ", row.ItemArray.Skip(2).Take(4).
        Select(Function(item) If(Not String.IsNullOrWhiteSpace(item.ToString()), item.ToString(), String.Empty)))
    row(2) = mergedData
End Sub)

Please find the below xaml

BlankProcess12.zip (49.1 KB)

Cheers!!

1 Like

Thanks for your input :slight_smile:

1 Like

Thanks for your input

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