How to split the datatable based on sum of volume

I have below data table. I need to split the table based on sum of volume.
If sum of volume is 62. Then we need to split.


Expected output :
First three row in in table1. next 2 row in table 2. next row in table 3.next three row in in table4.

We have any function in UiPath. Kindly suggest.

Hey @balanirmalkumar.s,

UiPath does not provide a direct function to split DataTable by column sum. You can loop through rows, keep a running total of Volume, and once it reaches 62, copy rows to a new DataTable and reset the counter. Use Filter DataTable or LINQ with Add DataRow in separate DataTables for the split logic.

Reference:

1 Like

Hi @balanirmalkumar.s

You can use the LINQ a/c to your requirements pls modify.

Dim tables As New List(Of DataTable)
Dim currentTable = inputTable.Clone()
Dim sum = 0

For Each row As DataRow In inputTable.Rows
sum += Convert.ToInt32(row(“Volume”))
currentTable.ImportRow(row)
If sum >= 62 Then
tables.Add(currentTable)
currentTable = inputTable.Clone()
sum = 0
End If
Next

If currentTable.Rows.Count > 0 Then tables.Add(currentTable)

Happy Automation

I tried above code in invoke code. I am getting below error. Invoke Code: Exception has been thrown by the target of an invocation.

@balanirmalkumar.s Please provide a sample input and output file reflecting your requirements, so we can better understand the scenario and find an appropriate solution.

Book2.xlsx (12.2 KB)

Sheet name
Input → Input data
Output → Expected output