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

image

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

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

@ainaasyhda

datatablevar.select(“[variable]=‘Value’”).copytodatatable

or you can try below

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

cheers

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

and for the second method, it shows error
image
image

thank you.

@ainaasyhda

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.

cheers

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;
image

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

@ainaasyhda

use

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.