How to Filter Datatable with Multiple Arrays

Hello!

My goal is to filter a datatable where at least one item in an array is contained in the datatable. I’m having trouble creating a long expression filtering for multiple arrays. The goal is to see all rows for which these conditions are met:

  • Any item in Array1 is contained in ColumnA
  • Any item in Array2 is contained in ColumnA
  • Any item in Array3 is obtained in ColumnB

Array1: {1,2,3} - contained in ColumnA
Array2 {9,8,7} - also contained in ColumnA
Array3 {A,B,C} - contained ColumnB

I was able to filter the datatable with one of the arrays:

FilteredDt = OriginalDt.AsEnumerable.Where(function (x) Array1.Any(function(y) x(“ColumnA”).ToString.Contains(y))).CopyToDatatable

Hi @benjiherb ,

Maybe you could try the below expression :

FilteredDt = OriginalDt.AsEnumerable.Where(function (x) Array1.Any(function(y) x("ColumnA").ToString.Contains(y)) orElse Array2.Any(function(y) x("ColumnA").ToString.Contains(y)) orElse Array3.Any(function(y) x("ColumnB").ToString.Contains(y))).CopyToDatatable
2 Likes

Thank you so much!!! This worked perfectly.

1 Like

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