Delete elements of a DataTable that are repeated in 2 DataTable's

Hi,
I have 2 DataTables which are vTabExport and vTabOld.
I want to delete the rows of vTabExport which the value of the vTabExport Columnindex 3 is the same as the value in vTabOld Columnindex 1.

I don’t know if there is an explicit activity to do this but, what I have been trying is to get the IndexNumber of the RowExport in order to later delete it.

What I have been trying is:
For each RowExport in vTabExport:

   For each RowOld in vTabOld:

           if RowExport(3).ToString.Trim=RowOld(1).ToString.Trim
                   
                    Assing IndexNumber = vTabExport.Rows.IndexOf(RowExport)

With this I get the IndexNumber of the vTabExport Row to be deleted but I don’t know how to delete it.
The assign activity is inside a For Each row Loop activity so, the RowExport cannot be deleted with the “Remove Data Row” activity because the index numbers of the rows are modified so the For Each row Loop cannot proceed.

I have been trying to have a list, an array or something similar to keep adding the IndexNumber’s but I can’t make it work.

Could someone help me please?
Maybe there is an easier way to carry out this process. I would be very glad to hear it.

PD: I have also tried the Add To Collection Activity but there is some error(s) regarding the type of Collection variable (Array or List).

Hi @nona,

Welcome to the UiPath Community :tada:

It’s hard to understand the requirement theoretically. Please share some sample data screenshot before and expected output.

Thanks,
Ashok :slight_smile:

Hey @nona

Try linq Given Below :
replace col2 with your Column name
It will give you ypur excepted Output

Your_dt1.AsEnumerable().Where(Function(y) Not Your_dt2.AsEnumerable().Select(Function(x) x(“col2”).ToString().Trim()).Contains(y(“col2”).ToString().Trim())).CopyToDataTable()

if it does’t work let me know .

Happy Automations ,
Cheers :upside_down_face:

Sorry for the confusion. I will clarify with an example:

Input: 2 DataTables

vTabExport:

Columna 1 Columna 2 Columna 3 Columna 4
A
B
C
D

vTabOld:

Columna 1 Columna 2
Z
T
A
V
C

The purpose is to delete the entire rows of the vTabExport Table (RowExport) on which the content of its columnindex 3: RowExport(3) is the same as the content of a Row of the vTabOld Table (RowOld) columnindex 1: RowOld(1)

So the condition which states which rows of vTabExport must be deleted is:
if RowExport(3).ToString.Trim=RowOld(1).ToString.Trim

In this example this occurs with the letters A and C.
This way, the expected output is to have the vTabExport table as the following one:

Output vTabExport:

Columna 1 Columna 2 Columna 3 Columna 4
B
D

Thank you for your time :):slight_smile:

Hi @nona

Please try this approach

image

image

image

DictCol = vTabOld.AsEnumerable().Select(Function(r) r("Column2").ToString.ToUpper.Trim).Distinct().ToDictionary(Function(k) k(0).ToString, Function(v) True)

Output

vTabExportOut = vTabExport.AsEnumerable().Where(Function(r) Not DictCol.ContainsKey(r("Column3").ToString.ToUpper.Trim)).CopyToDataTable()

image

xaml File : FilterDT1ByColumnValuesInDT2.xaml (13.6 KB)

Thanks!

1 Like

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