Filtering a data table for duplicate column values

Hello folks,

I have a data table that looks like this…

Column 1 | Column 2 | Column 3

  1        |        1        |        1

  2        |         2       |        2

  3        |         3       |        2

  4        |         4       |        3

  5        |         5       |        4

And what I want to do is basically “split” that table into two table based on duplicates in Column three show in the end I should get these guys…

Column 1 | Column 2 | Column 3

  2        |         2       |        2

  3        |         3       |        2

Column 1 | Column 2 | Column 3

  1        |        1        |        1

  4        |         4       |        3

  5        |         5       |        4

I could toss this into excel and handle it easy but I am trying to see if I can’t do it through just UiPath data tables. Any advice is appreciated.

1 Like

Do you need put “Duplicated rows” apart in other DataTable?

Yes sir I do.

I’m Think in a SQL Style that could be possible to reproduce in UiPath

let’s say we have this table:

Column1|Column2|Column3 
1      |  1    |  1
2      |  2    |  2
3      |  3    |  2
4      |  4    |  3
5      |  5    |  4
  1. Get Duplicates in Column3: Count values in Column3
    select column3, COUNT(colum3) from mytable group by column3 having COUNT(column3) >1
    image

  2. Take Column3 values from previous step
    select column3 from mytable having count(column3) > 1

  3. Filter Original Datatable with previous values and put results in a new datatable.
    http://www.csharp-examples.net/dataview-rowfilter/
    https://www.dotnetperls.com/datatable-select

Hey @FireflySeason2

you can do using Datatables

Datatable DuplicateResults =  YourDatatableName.AsEnumerable.GroupBy(function(x) x("YourColumnName i.e Column3")).Where(function(x) x.Count() > 1).SelectMany(function(g) g).ToArray().CopyToDatatable;

Datatable UniqueRecords = YourDatatableName.AsEnumerable().GroupBy(Function(x) x("YourColumnName i.e Column3")).Where(Function(x) x.Count = 1).SelectMany(Function(x) x).ToArray.CopyToDataTable;

See my attached Sample for your better understanding and reference :slight_smile:
ColumnDuplicateSample.xaml (8.6 KB)

Regards…!!
Aksh

5 Likes

Hi @FireflySeason2

Use this post Duplicate rows in data table

Thanks
Ashwin.S

That worked great. Thanks a lot.

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