Use Variable to filter datatable

Hi I want to filter the datatable get from excel.
Instead of filtering using the column name, I want to sent the column name as variable which the colum will be varied.
I assign a variable to represent the column which the colum is date


And I write the Expession in the filter assign like this :

I tried this method however failed. Kindly advised on how should I use this filter method with variable


or you can try below

datatable.asenumerable.where(function(r) r(“ColumnName”).tostring=“OD”).copytodatatable


Hi thank you for your reply, however still could not found the table name with using the variable

and for the second method, it shows error

thank you.


can you check the columns of the datatable using below syntax

datatable.columns gives you all the column which you have in the datatable

and check the column which you have passed in the variable is there are not

Outputdt=Inputdt.asEnumerable.where(Function(row) row(Variable).equals(“OD”)).CopytoDatatable.


Hi @ainaasyhda

Check the below linq expression

Outputdt = Inputdt.asEnumerable.Select(Function(row) row(Variable).equals("OD")).CopytoDatatable.

Note - In the Variable pass the variable which stores the column name.

Hope it helps!!

Hi can I know the variable type for “Outputdt”, is it data table?
Also it showing error;

Thanks :wink:

I have made a small wrong

Use the below one

Inputdt.AsEnumerable.Where(Function(row) row(Variable).equals("OD")).CopyToDataTable

Hope you understand!! @ainaasyhda



Outputdt = Inputdt.asEnumerable.where(Function(row) row(Variable).equals(“OD”)).CopytoDatatable

it will helps

Yay its working thank you!!!

1 Like

its working !! thank youuu

1 Like

Thank you @ainaasyhda

Happy Automation!!

1 Like

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