Delete rows containing blank values by deleting duplicate values in item A in the data table, leaving only those with higher values in item B

Hey there!

I was previously taught how to delete rows containing duplicate and blank values in a data table.
This time I would like to know how to delete duplicate values in item A, leaving only those with high values in item B, and how to delete rows containing blank values.

Is it possible to do that?

I will post the code you taught me before and a link to the code.

BBBB = AAAAA.AsEnumerable.Where(Function(x) Not (String.IsNullOrEmpty(x("A").ToString) OrElse x("A").ToString.Contains("KEYWORD"))).CopyToDataTable()

Hi,

How about the following? i think it’s better to remove blank rows then grouping.

img20220307-1

dt.AsEnumerable.Where(Function(r) r("A") IsNot Nothing AndAlso (not String.IsNullOrEmpty(r("A").ToString))).GroupBy(Function(r) r("A").ToString).Select(Function(g) dt.Clone.LoadDataRow({g.Key,g.Max(Function(r) Int32.Parse(r("B").ToString))},False)).CopyToDataTable

Sample20220307-1.zip (8.6 KB)

Regards,

1 Like

Hi Yoichi!

You are always there to help when I need it!
Thanks for getting the data ready for me!

Your code worked perfectly!
It is so wonderful.

But there is something I omitted.
There are actually multiple other columns, not just columns A and B.
Is there any way to retrieve all of those rows, not just A,B?

Sorry for the trouble.

Hi,

Can you try to modify arguments of LoadDataRow as the following?

dt.AsEnumerable.Where(Function(r) r("A") IsNot Nothing AndAlso (not String.IsNullOrEmpty(r("A").ToString))).GroupBy(Function(r) r("A").ToString).Select(Function(g) dt.Clone.LoadDataRow({g.Key,g.First().Item("A-1"),g.First().Item("A-2"),g.Max(Function(r) Int32.Parse(r("B").ToString)),g.First().Item("B-2")},False)).CopyToDataTable

Sample20220307-1v2.zip (8.8 KB)

Regards,

1 Like

You are always perfect!
Worked for exactly what I wanted!!!

You are a hero for always helping me out!
Thank you so much!

1 Like

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