cancel
Showing results for 
Search instead for 
Did you mean: 

Collection - Remove Duplicated Values in Specific column

MateuszWojcik
Level 5
Hello,

I have action which remove duplicated rows in whole collection. 
Collection_Out = Collection_In.DefaultView.ToTable(True)

I want to write new action which remove duplicates value only in specific column.

Does anyone have solution for this?

Thank you in advance

------------------------------
Mateusz Wojcik
RPA Programist
Rockwell Automation
Europe/Warsaw
------------------------------
1 BEST ANSWER

Helpful Answers

Dim c As Integer
c=Cint(cNumber)
Collection_Out = Collection_In.AsEnumerable().GroupBy(Function(row) row(c)).[Select](Function(group) group.First()).CopyToDataTable()

Add cNumber as Number Input  referring to column number starting from index 0
ALso add following to Imports

24065.png

 



------------------------------
Gopal Bhaire
Analyst
Accenture
------------------------------

View answer in original post

12 REPLIES 12

RaúlHernández
Level 5

Hi, Mateusz.

 

You can try to use the asset from Digital Exchange called Millicom – Collection Utility.

 

You can find the action the extract unique values (or remove duplicates) from a collection and other nice actions to work with collections.

 

 

 

 24034.jpg

 

 



------Original Message------

Hello,

I have action which remove duplicated rows in whole collection. 
Collection_Out = Collection_In.DefaultView.ToTable(True)

I want to write new action which remove duplicates value only in specific column.

Does anyone have solution for this?

Thank you in advance

------------------------------
Mateusz Wojcik
RPA Programist
Rockwell Automation
Europe/Warsaw
------------------------------

Good Suggestion by Raúl Hernández, and if you are not allowed to import a VBO, you can sort your collection on the the same field where you expect duplicates, and run a loop on it as long as you find the currentrow.column value = lastrow.cloumn value, you can delete the current row.

or you can choose to write a code stage as well.

------------------------------
Ishan Mahajan
India
------------------------------

Raúl Hernández I do not see those actions in Millicom – Collection Utility. Please see attachment
24045.png

Ishan Mahajan thank you for this solution.

I am wondering if there is a way to extand code Collection_Out = Collection_In.DefaultView.ToTable(True). This will contains less stages. than looping through whole collection.




------------------------------
Mateusz Wojcik
RPA Programist
Rockwell Automation
Europe/Warsaw
------------------------------

I think you can use DISTINCT to get the result you need.

 

Try it and lets see if works.

 

 24049.jpg

 

 



------Original Message------

Raúl Hernández I do not see those actions in Millicom – Collection Utility. Please see attachment
24050.png

Ishan Mahajan thank you for this solution.

I am wondering if there is a way to extand code Collection_Out = Collection_In.DefaultView.ToTable(True). This will contains less stages. than looping through whole collection.




------------------------------
Mateusz Wojcik
RPA Programist
Rockwell Automation
Europe/Warsaw
------------------------------

DISTINCT  action return a collection with unique values and column counter 
I lost others columns.
24052.png
Please see attachments


------------------------------
Mateusz Wojcik
RPA Programist
Rockwell Automation
Europe/Warsaw
------------------------------

I understand.

 

In that particular case, you can use a simple loop logic to get unique values from the collection.

 

Simple loop logic should use

  • A mirror collection, to compare all elements.
  • A new collection to store unique values (entire row).
  • A loop inside other loop, to compare all elements.
  • a Flag to identify if the element already exist in your new Collection.

 

 

This logic is high time consuming depending of the numbers of rows in your collection, but it will work.

 

 24057.jpg

 

 



------Original Message------

DISTINCT  action return a collection with unique values and column counter 
I lost others columns.
24058.png
Please see attachments


------------------------------
Mateusz Wojcik
RPA Programist
Rockwell Automation
Europe/Warsaw
------------------------------

Raúl Hernández thank you for this solution.

I am looking for less time consuming way, like extanding code Collection_Out = Collection_In.DefaultView.ToTable(True) by additional argument or additional line.

------------------------------
Mateusz Wojcik
RPA Programist
Rockwell Automation
Europe/Warsaw
------------------------------

Dim c As Integer
c=Cint(cNumber)
Collection_Out = Collection_In.AsEnumerable().GroupBy(Function(row) row(c)).[Select](Function(group) group.First()).CopyToDataTable()

Add cNumber as Number Input  referring to column number starting from index 0
ALso add following to Imports

24065.png

 



------------------------------
Gopal Bhaire
Analyst
Accenture
------------------------------

Hi Gopal Bhaire

This is want I was looking for.
It works.

Thank you very much.

------------------------------
Mateusz Wojcik
RPA Programist
Rockwell Automation
Europe/Warsaw
------------------------------