Filter a data table based on a column in another data table

Hi,

I have two data tables, Consider first DT contains a list of 100 products and the second DT contains a list of 25 products.

I want to filter the first datatable with the 25 products from second DT and display only the line items for those 25 products from first DT…

Please let me know how to do this

in some cases we can do it with the help of:

  • data joins
  • lookups

Give a try at following LINQ approach

Assign activity:
LHS: dtResult | DataType: DataTable
RHS:

(From d1 in dtProds.AsEnumerable
Let chk = dtList.AsEnumerable.Any(Function (d2) d2(YourColNameOrIndex).toString.Equals(d1(YourColNameOrIndex).toString.Trim))
Where chk
Select r=d1).CopyToDataTable
1 Like

What’s dtProds in this expression?

D1 and D2 are the two data tables right? but I m not sure what dtProds means

use your variablename whenever you see dtProds within the LINQ statement

use your variablename whenever you see dtList within the LINQ statement

d1,d2 are like local variable names referencing the looped datarows

Also have a look here:
:ambulance: :sos: [FirstAid] Handling of The source contains no DataRows exception - News / Tutorials - UiPath Community Forum

And here for LINQ
[HowTo] LINQ (VB.Net) Learning Catalogue - Help / Something Else - UiPath Community Forum

Can you please let me know how to compare two columns ? For example Dt1 has product as AC and ID as 1 then we should filter DT2 for product AC and ID 1
If there are line items with Product - AC and ID - 2 it must not be considered.

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