Remove duplicate row if one column is blank

Hi Everyone.

I want to remove duplicate row with LinQ in datatable.

The datatable as below picture and attached file. I want remove the duplicate rows if the value at “status” column is blank…

The Input Table:
image

The Output Table:
image

Thanks in advance!
Book1.xlsx (8.3 KB)

Hi,

Can you try the following expression?

result = dt.AsEnumerable.Where(Function(r) r("status") isnot Nothing AndAlso (not String.IsNullOrEmpty(r("status").ToString))).CopyToDataTable

Or

Probably, you can also use FilterDataTable activity to achieve it.

Regards,

1 Like

Hi @Mr.H

You can make use of the Filter Data Table as in the below inline screenshot.

image

Hope this will be helpful. Thank you.

1 Like

Hi Bro.

No, i want to delete the duplicate rows in datatable.

In the input datatable, i have 3 duplicate rows… but it only remove the duplicate row which is null at “status” column.

In the actual data, it has many row null or not null at “status” column.

Hi,

I had misunderstanding your requirement.
How about the following expression?

result = dt.AsEnumerable.GroupBy(Function(r) r("item").ToString).SelectMany(Function(g) g.Where(Function(r) r("status") isnot Nothing AndAlso (not String.IsNullOrEmpty(r("status").ToString)))).CopyToDataTable

Regards,

1 Like

Thanks you very much Bro!

1 Like

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