Comparing two Collections and providing unique value output - Narrowing down based on 1 field

RReed

New Member
Hi all,

I know this was somewhat answered via https://www.rpaforum.net/threads/comparing-two-collections-and-and-saving-unique-values.14717/

But I would like to see if there is a way to further narrow down a comparison using code stage for Blue Prism.

The given code is the following: Collection_3 = Collection_2.AsEnumerable().Except(Collection_1.AsEnumerable(), DataRowComparer.Default).CopyToDatatable()

While the code for the collection comparison works when it comes to handling just 1 field within each of the collections. If we are to compare collections that have 2 or more fields, due to the current logic, it would compare between all fields to find unique values.

Is there a way to add onto the coding where we are comparing just 1 specific field between two collections to get unique values?

Ex:

Collection 1 & 2 have fields: Street & Votes

What I am trying to get is just unique values from the field Street only.
 

sahil_raina_91

Active Member
Hi all,

I know this was somewhat answered via https://www.rpaforum.net/threads/comparing-two-collections-and-and-saving-unique-values.14717/

But I would like to see if there is a way to further narrow down a comparison using code stage for Blue Prism.

The given code is the following: Collection_3 = Collection_2.AsEnumerable().Except(Collection_1.AsEnumerable(), DataRowComparer.Default).CopyToDatatable()

While the code for the collection comparison works when it comes to handling just 1 field within each of the collections. If we are to compare collections that have 2 or more fields, due to the current logic, it would compare between all fields to find unique values.

Is there a way to add onto the coding where we are comparing just 1 specific field between two collections to get unique values?

Ex:

Collection 1 & 2 have fields: Street & Votes

What I am trying to get is just unique values from the field Street only.
If you are seeking unique values from both the collections combined, wouldn't merging the collection and removing duplicates based on "Street" column serve the purpose ?
 

RReed

New Member
If you are seeking unique values from both the collections combined, wouldn't merging the collection and removing duplicates based on "Street" column serve the purpose ?



Hi Sahil, that was actually what we tried using first but it didn't turn out too well mainly because we only wish to have the unique values only while the remove duplicate will still give us one of those values back.


For example here is what would be how the collection would look like:

Collection 1 would have something like this:

StreetVotes
123 ABC ST100
456 DEF ST150
098 RPA ST260
999 CEF ST300
789 TOP ST500



Collection 2 would have this:

StreetVotes
123 ABC ST 100
456 DEF ST 256
789 TOP ST500


What we wish to get would be:

StreetVotes
098 RPA ST260
999 CEF ST300
 
Last edited:

sahil_raina_91

Active Member
Hi Sahil, that was actually what we tried using first but it didn't turn out too well mainly because we only wish to have the unique values only while the remove duplicate will still give us one of those values back.


For example here is what would be how the collection would look like:

Collection 1 would have something like this:

StreetVotes
123 ABC ST100
456 DEF ST150
098 RPA ST260
999 CEF ST300
789 TOP ST500



Collection 2 would have this:

StreetVotes
123 ABC ST100
456 DEF ST256
789 TOP ST500


What we wish to get would be:

StreetVotes
098 RPA ST260
999 CEF ST300
Gotcha!

Here is the code. Hope it helps:

Collection_3 = Collection_1.Rows.OfType(Of DataRow)().Where(Function(a) Collection_1.Rows.OfType(Of DataRow)().[Select](Function(k) Convert.ToString(k("Street"))).Except(Collection_2.Rows.OfType(Of DataRow)().[Select](Function(k) Convert.ToString(k("Street"))).ToList()).Contains(Convert.ToString(a("Street")))).CopyToDataTable()
 
Top