Filter DT by multiple variable values

Hi all,

I have a DT (dt_390) that I need to filter for all the POs that can be in my array (of String) arrStr_POs.

What I found here is working:

dt_390Filtered = dt_390.AsEnumerable.Where(Function(r) arrStr_POs.Contains(r(“PO No.”).ToString)).CopyToDataTable

BUT! It’s only working when I have an exact match within the array.

I can have following input (arrStr):
{“12345”, “67890”, …}
But in my table it can be displayed as AB1C12345 and AB1A67890.
So what I need is something like:
“When Item"PO No”.ToString ENDSWITH one of the arrStr items, then copy to datatable".

I already have a solution in place (iterating through each PO No of my ArrStr, filtering the DT, perform other stuff, take next item of ArrStr), it’s much more complex.
Just wanted to know if it’s possible to apply a filter for all PO-items at once (like you would use “Add current selection to filter” in Excel.

(Also tryed .select method, but I can’t seem to get the operator (?) correct with LIKE ‘%…%’ in the query. Because this also seems to look for a match of the DT-Item in the array and not of the Array-item in the DT:
dt_390Filtered = dt_390.Select(“[PO No.] IN ('” + str_ArrPOs + “')”).CopyToDataTable)

Thanks for any suggestions! :slight_smile:

EDIT after topic was closed:
Thank you both, @ashokkarale and @Anil_G, this worked perfectly! :smiley:

Contains will match those, unless you have extra spaces or something in PO No

@Juli,

Try this:

dt_390Filtered = dt_390.AsEnumerable().
Where(Function(r) arrStr_POs.Any(Function(po) r("PO No.").ToString().EndsWith(po))).
    CopyToDataTable()

Thanks,
Ashok :slight_smile:

1 Like

@Juli

You can extend your linq query as below

dt_390Filtered = dt_390.AsEnumerable.Where(Function(r) arrStr_POs.Any(function(x) r("PO No.").ToString.EndsWith(x)).CopyToDataTable

Cheers

1 Like

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