How to filter with the List of values in a column

They are list of values, the list of values should be filtered in a particular column. How to do that

you can add multiple filter & elaborate your query to get exact answer
Regards,
Arivu

there are 4 values , with that values I have to filter a column in a excel sheet

Filter in same column or different columns?

if same column

dt.Select("column1='Value1' or column1='Value2' or column1='Value3' or column1='Value4'").CopyToDataTable()

if different column

dt.Select("column1='Value1' and column2='Value2' and column3='Value3' and column4='Value4'").CopyToDataTable()

diff sheet diff column

filtered values are dynamic, they are stored in a variable.

HI @anjani_priya ,

kindly share the input and expected output as screenshot.

Regards,
Arivu

dt.Select(“column1='”+strValue1+“’ and column2='”+strValue2+“’ and column3='”+strValue3+“’ and column4='”+strValue4+“'”).CopyToDataTable()

Regards,
Arivu

sheet1.xlsx (10.3 KB)
col2 in sheet1 should be filtered in sheet2
sheet1 col2 values are also filtered values, they are filtered based on col3, if col3 has -1,1,0 then it should filter. I got logic to filter col3 but I cant filter the list of values from col2 sheet1 in col2 expected sheet

There is no “Sheet2” in your excel

(From p in dtSheet1.Select() where( From q in dtSheet2.Select() where q(“ColumnName”).Equals(p(“ColumnName”)) Select q).ToArray.Count>1 Select p).ToArray.CopyToDataTable()

Regards,
Arivu

iam sorry its Expected sheet

(From p in dtSheet1.Select() where(From q in dtExpected.Select() where q("col2").Equals(p("col2")) Select q).ToArray.Count>1 Select p).ToArray.CopyToDataTable()

Regards,
Arivu

error source contains no datarows but dtsheet1 and dtexpected contains values

can you share the screenshot and error message

have you read both the datatable? can you share the xaml file

Try below query
(From p in dtSheet1.Select() where(From q in dtExpected.Select() where q("col2").Equals(p("col2")) Select q).ToArray.Count>0 Select p).ToArray.CopyToDataTable()

Regards,
Arivu

Same error iam getting

Hey @anjani_priya
Can you Provide the input file for Better understanding
and mention your query below of file how you the want output .

sheet1.xlsx (10.3 KB)
col2 in sheet1 should be filtered in expected sheet col2
I cant filter the list of values from col2 sheet1 in col2 expected sheet

1 Like