Asking for a better way of Dividing Datable and Looping in them

First of all, I am sorry for I am new at Uipath and is doing the everything in a long way.
Currently, I have a filtered Datatable that contains a column(Currency) which contains either “Foreign” or “Local”. I need to filtered this filtered Datatable again by “Foreign” and “Local” rows(Two DTs now) then do a for each for both of them. Excluding this step, I already did two for each loops, and I think that doing it will mess up my workflow more. Is there a better way of dividing/filtering a Datatable into two and use only one for each for both filters? Thank you.

1 Like

Hi @Archie

We can split the datatable into two dt like this

For rows containing only Foreign

Dt1 = Maindt.AsEnumerable().Where(Function(a) a.Field(of String)(“yourcolumnname”).ToString.Contains(“Foreign”)).CopyToDatatable()

For rows containing only Local

Dt2 = Maindt.AsEnumerable().Where(Function(a) a.Field(of String)(“yourcolumnname”).ToString.Contains(“Local”)).CopyToDatatable()

This will Dt1 and Dt2 with which you can now use a for each loop based on your process

Where Dt1 and Dt2 are datatable variable defined in Variable Pabel with default value as New System.Data.Datatable

Hope this would help you resolve this issue

Cheers @Archie

1 Like

Yes @Archie. Its possible for sure with Linq queries.

If you can provide a sample datatable, it will be helpful to provide you a sample solution.

Thanks
#nK

1 Like

I get it with the LINQ part. I also did that with filtering my Main DT by Distinct Date(from Date Column). What I am hoping to do is, after filtering it again using LINQ. Is it possible to Use the New DTs(DT1 and DT2), in only one for each loop, because the activities that I’ll input inside the for each loop, are quite a lot. I am just hoping if it’s possible, If not then it’s ok. I could always do it the normal way.

1 Like

I hope now i understood your issue.

Yes you can just go with only one foreach please…

Don’t even split the DT (which you did with linq previously)

  1. From the master DT, iterate through ForeachRow

  2. Inside that add an if block to find foriegn or other currency, based on that you can add respective currency activities in true & others in else block.

This way will have one foreach with actual business logic for both currency types inside based on a condition.

Thanks
#nK

1 Like

Thanks. I forgot that I can always do this. Thanks again for the help

1 Like

Rock it ! :slight_smile:

1 Like

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