Find and remove matching values in collections

Burks

New Member
Hi,

As part of a larger process I need to sort through Collection A which contains around 5,000 rows at a time against Collection B which can contain a small amount of rows from around 10-30 and if any of the values from B match A then the rows from A need removing.

I have attempted this by doing the following after finding a suggestion on these forums but due to the amount of rows we're processing it's simply taking too long. Is there a better way of doing this? N.B that rather than looking for unique values like mentioned in that post, I changed the logic to look for matching.

Example.png

I did consider merging the collections and deleting any duplicates and then from the deleted items delete the matching rows within the merged collection although not sure how this could actually work with the available utilities.

Thanks.
 

sahil_raina_91

Active Member
Hi,

As part of a larger process I need to sort through Collection A which contains around 5,000 rows at a time against Collection B which can contain a small amount of rows from around 10-30 and if any of the values from B match A then the rows from A need removing.

I have attempted this by doing the following after finding a suggestion on these forums but due to the amount of rows we're processing it's simply taking too long. Is there a better way of doing this? N.B that rather than looking for unique values like mentioned in that post, I changed the logic to look for matching.


I did consider merging the collections and deleting any duplicates and then from the deleted items delete the matching rows within the merged collection although not sure how this could actually work with the available utilities.

Thanks.
I have answered this question here : https://www.rpaforum.net/threads/co...nd-and-saving-unique-values.14717/#post-31349
 

Burks

New Member
Thanks Sahil.

For anybody having this issue, just use Sahil's code but swap the columns round:

Collection_3 = Collection_2.AsEnumerable().Except(Collection_1.AsEnumerable(), DataRowComparer.Default).CopyToDatatable()

This returns unique values

Collection_3 = Collection_1.AsEnumerable().Except(Collection_2.AsEnumerable(), DataRowComparer.Default).CopyToDatatable()

This returns matching values
 
Top