Combining dates and data from multiple rows

Tasks Completed_Raw Data.xlsx (11.8 KB)

Hello UiPath Community,

Is it possible with UiPath to combine the dates and data from several rows?
See enclosed for the raw data and the expected result for each date that correctly adds the data for each row corresponding to each date.
Tasks Completed_Expected Result.xlsx (10.8 KB)
Thank you for any help you can provide.
Regards

Hi @PPIM_RPA
=> Use Read Range Workbook to read the excel and store it in an data Table variable.
=> Use the below code in Invoke Code activty:

Dim inputDataTable As DataTable = YourInputDataTable.Clone() ' Clone the structure of the input DataTable
Dim outputDataTable As DataTable = inputDataTable.Clone()

For Each row As DataRow In YourInputDataTable.Rows
    ' Extract the date part only
    Dim currentDate As String = DateTime.ParseExact(row("Date").ToString(), "MM_dd_yyyy hh.mm tt", CultureInfo.InvariantCulture).ToString("MM_dd_yyyy")

    ' Check if the date is already in the outputDataTable
    Dim existingRows As DataRow() = outputDataTable.Select("Date = '" & currentDate & "'")

    If existingRows.Length > 0 Then
        ' If the date is present, update the sums
        existingRows(0)("Tasks Completed") = CInt(existingRows(0)("Tasks Completed")) + CInt(row("Tasks Completed"))
        existingRows(0)("Minutes Saved") = CDbl(existingRows(0)("Minutes Saved")) + CDbl(row("Minutes Saved"))
    Else
        ' If the date is not present, add a new row to the outputDataTable
        Dim newRow As DataRow = outputDataTable.NewRow()
        newRow("Date") = currentDate
        newRow("Tasks Completed") = CInt(row("Tasks Completed"))
        newRow("Minutes Saved") = CDbl(row("Minutes Saved"))
        outputDataTable.Rows.Add(newRow)
    End If
Next

YourOutputDataTable = outputDataTable

Below are the Invoked arguments:

=> Use Write Range Workbook to writr the datatable back to excel.
Input:


Workflow:

Output:

xaml:
Sequence1.xaml (9.8 KB)

Hope it helps!!
Regards

1 Like

Thank you so much. Appreciate your help.

1 Like

You’re welcome @PPIM_RPA

Happy Automation

Regards

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