Excel Manupulations IGetting all the data of the selected column from inputDT to OutputDT, however want only that data which satisfy my if condition

Excell_Manupulations.zip (54.5 KB)

Attached is my program, where I want the data of 3 columns on the basis of “if condition”, however after execution getting all the data of the input datatable with the data according to the “If condition” in the output.xls file.

Using this method:
“inputDT.DefaultView.ToTable(true,“Name”,“Subjects”,“Marks”)”

Can anyone please help here to resolve the issue.

I am not sure what’s your condition requirement but you can use Select command. e.g. DataTableObj.Select(“col1=‘value1’”) it will return you the DataRow object which you can just iterate through general for each loop and do whatever you want.

1 Like

@servesh20

Welcome to the uipath community.

You want to filter some data from Excel file and want to write in other excel file.

If yes then you can use Select Query or Filter DataTable activity to filter data. Below is the sample expression for select query.

   newDT = inputDT.Select("[Column1] = 'Value' AND [Column2] = 'Value' AND [Column3] = 'Value'").CopyToDataTable
1 Like

@lakshman @aman.kumar.monga.09

The above expression is working fine if you want to fetch selected rows from the input excel file.
My issue is that…I want to keep only the selected header column from my input excel file and data based on only my if condition. My program was working if i use the method DefaultView.totable(true, “column1”, “column2”). It returns the selected columns but all the records of input excel file as well and i want only those records which satisfy the if condition only. If you run my above program you see that the output.xlsx file is generated with all the records that are in input excel and also records which comes from the if condition.
Input%20excel%20file Output

Refer My Screenshots of input and output fie…I want only 2 records in the output file not all the records.

I also used “inputDT.clone” method, it works but all columns are returned and i want selected columns only.

1 Like

@servesh20

Then do one thing. You can try my expression after yours like below.

          newDT = inputDT.DefaultView.totable(true, “Name”, “Subjects”,"Marks").CopyToDataTable

         filterDT = newDT.Select("[Name] = 'Value' AND [Subjects] = 'Value' AND [Marks] = 'Value'").CopyToDataTable
1 Like

@lakshman
This expression is giving error as “the source contains no data rows”. However i found one alternative of doing this is by using the build data table concept.
Define all the columns that you want under build data table and make it clone of that to output datatable and using add data rows read the values.

1 Like

@servesh20

Could you please show me screenshot of the expression you mentioned here. Will check it once.

1 Like

excelDT_Manupulations.zip (54.8 KB)

@lakshman
Please refer the attached xaml program for the alternative that i used.