Segregating an excel file depending on its "Branch" column using LinQ

Hi,

Good Day.

May I know how to segregate this excel file depending on its branch using LinQ to make the execution faster where each Branch will be put on a separate sheet? Kindly see below for the desired outputs and attached file (Sample_Reports.xlsx)

Desired outputs:

Sample_Report.xlsx (28.9 KB)

Thank you.

Best regards,
Llessur

@Llessur
have a look here for some general concept options:
[HowTo] Overview on different options for grouping data and processing the groups - News / Tutorials - UiPath Community Forum

Linq Approach:

Assign Activity:
TableList | Datatype: List(Of DataTable) =

(From d in YourInputDataTableVar.AsEnumerable
Group d by k=d("Branch").toString.Trim into grp=Group
Select t=grp.CopyToDataTable).toList

Then loop over TableList (e.g For each activity) and write it down to excel

Hi @Llessur

Yes you can use the LINQ Expression, check the below steps,
→ Use the Read range workbook activity to read the Input excel and store in a datatable called dt_Input.
→ Then use the For each activity and give the below LINQ Expression in For each,

dt_Input.AsEnumerable().GroupBy(Function(row) row.Field(Of String)("Branch")).Select(Function(group) group.CopyToDataTable()).ToList()

→ Open properties of For each and in the argument type dropdown select the System.Data.Datatable.
→ Inside for each insert the assign activity to get the name of the branch by using LINQ Expression,

- Assign -> SheetName = dt_Input.AsEnumerable.FirstOrDefault(Function(x) Not String.IsNullOrEmpty(x("Branch").ToString()))("Branch").ToString()

→ After assign activity insert the Write range workbook activity and give the path of the input excel file, SheetName variable in the Sheet name field and output of for each activity in datatable field.

Check the below workflow for your reference,

Hope it helps!!

1 Like

Hi @Llessur

BranchSeperation.zip (44.0 KB)

The requirement works!

Hope this helps

1 Like

Hi @Sanjay_Bhat what would be the work around if I will try to segregate the Branches to different excel files? Thank you

@Llessur

You can pass something like this!

Hope this helps!

1 Like

I tried to do the same thing. Thank you so much.

1 Like

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