Filter data on excel data table

Hello guys I have this datatable “WEIGHT”


I need to filter these data with those weight that only contains 250 lbs below and put it into another sheet.

My only problem is that I can’t filter it on the filter data table activity, because WEight data is “250 lbs”. it has the “lbs”

note: Weight value should be configurable

Hi @shanti_18

→ Use Read range workbook activity to read the excel and store in a datatable variable called Input_dt.
→ Take an assign activity and give the below linq expression,

- Assign -> Out_dt = (From row In Input_dt
                      Where CInt(row("WEIGHT").toString.Split(" ").First) < 250
                      Select row
                        ).CopytoDatatable()

→ Use Write range workbook activity to write the Output_dt variable to another sheet in the excel.

Check the below workflow for better understanding,

Input -
image

Output -
image

Hope it helps!!

Hi @shanti_18

In value sections give the value as 250 lbs

Regards

Hi @shanti_18

Can you try below query

dtFiltered = dtOriginal.AsEnumerable() _
    .Where(Function(row) 
        If(row("Weight") IsNot Nothing AndAlso row("Weight").ToString().ToLower().Contains("lbs"), 
           CInt(row("Weight").ToString().ToLower().Replace("lbs", "").Trim()) <= 250, 
           False)
    ).CopyToDataTable()

Hi,

How about the following if there is possibility the result is empty?

 arrDr =v dt_WeightPlyaers.AsEnumerable.Where(Function(r) System.Text.RegularExpressions.Regex.IsMatch(r("WEIGHT").ToString,"\d+") AndAlso CInt(System.Text.RegularExpressions.Regex.Match(r("WEIGHT").ToString,"\d+").Value)<250).ToArray()

note: arrDr is DataRow array type

Regards,

where can i find it?
you mean this ?

Hi @shanti_18

Yes if the in-weight variable contains the value of 250 then the filteration given by you is correct.

Regards

it’s not working brother.

Hi @shanti_18

Try giving the 250 lbs directly in the place of in-weight variable and also remove the second filteration and give a try bro

Regards

We can’t do it with both of the Excel activities and datatables. It will throw the error for sure.

Instead of doing this use the workbook activities and linq expression it will take less time and work properly.

Download the below workflow and execute in your machine,
2024.xaml (17.3 KB)

Note - Change the name of the Excel file and sheet names.

Hope you understand!! @shanti_18

Hi @shanti_18

Try replicating the same process from the below xaml file. Change the excel file names and sheet names as required.
Sequence15.xaml (11.2 KB)
Input:


Output:

Workflow:

Filter Wizard:

Regards

Hi @shanti_18

Make the variable Weight datatype as System.Int32 and you can pass that in Filter Datatable table wizard.

Regards

Hi @shanti_18

Please remove the variable and argument and re-initialize them and that might sort out the issue.

Regards

Hi @shanti_18

Check out the below workflow:
Sequence15.xaml (11.6 KB)

Regards

1 Like

alright got it bro, thank you so much.

I add variable that will handle my argument value.

If you got your solution for your query please mark my post as solution to close the loop or if you have any questions, let me know @shanti_18

Happy Automation!!

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