Merge duplicates in one datatable

Hello, I have a question.
In one data table, based on the column (Product no), I want to make the same things in one line as shown below the arrow.
The column looks simple now, but in reality, the value of a column may be empty and there may be a value.
It’s a single data table, how can I combine them?

Hi @testbb ,

Could you maybe check the below Post :

It should be able to get you the required output.

Although, as in the workflow, you would not need to use Merge Datatables Activity, since the data that you have is already a merged one.

Also, The Grouping needs to be done by 3 columns, The Linq Expression could be modified to the below :

	From row In dt.AsEnumerable()
	Group row By k = row("Size").ToString.Trim, a = row("Product no").ToString.Trim, b = row("qty").ToString.Trim
	Into grp= Group
	Let lt = grp.Select(Function(g) arrColSet.Select(Function(cn) Tuple.Create(cn, g(cn)))).SelectMany(Function(t) t)
	Let ltf = lt.Where(Function(t) Not (IsNothing(t.Item2) OrElse String.IsNullOrEmpty(t.Item2.ToString.Trim)))
	Let ra= arrColSet.Select(Function(c) ltf.Where(Function(t) c.Equals(t.Item1)).DefaultIfEmpty(New Tuple(Of String, Object)(c, Nothing)).First().Item2).ToArray
	Select r = dtResult.Rows.Add(ra)

Let us know if you are facing any issues with the usage of the linq or the post provided.

1 Like

Is it possible to use only Product no as a criterion instead of other columns?
Other columns may or may not be present.
But there is always only Product no.

@testbb ,

You could remove the Grouping on the other columns, changing from the below :

Group row By k = row("Size").ToString.Trim, a = row("Product no").ToString.Trim, b = row("qty").ToString.Trim

To the below :

Group row By a = row("Product no").ToString.Trim

As you said, I did it with an image.
But I get an error that the value cannot be null.
I need help.

@testbb ,

Could you let us know if the data is in the format as mentioned previously ?

Do we have a change from the previous data provided ? We would like to inspect the data so we could understand where it is failing.

Yes. It’s the same thing.

Is the structure I used correct?
After reading range in Excel Application Scope, I put what you said in Assign.

@testbb ,

Could you check or provide the Screenshot of the whole workflow ?

Is by any chance some activities been deleted ? like the one below :

thank you
Actually, the process you mentioned was missing!!
thank you!!!

1 Like

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