i need to find duration seconds-time taken seconds= delay second
LINQ:
dt.AsEnumerable().Select(Function(row) dtOutput.Rows.Add(row("Duration"), row("Time Taken"), (TimeSpan.Parse(row("Duration").ToString) - TimeSpan.Parse(row("Time Taken").ToString)).TotalSeconds.ToString("F6"))).CopyToDataTable()
Output:
Sample Code:
Workflow.xaml (9.2 KB)
Thanks,
Ashok
is not working kindly update the same
Can you please try this workflow, below is the code used in invoke code activity
dtInput.AsEnumerable().ToList().ForEach(Sub(row)
Dim durationTime = TimeSpan.Parse(row("Duration").ToString())
Dim timeTaken = TimeSpan.Parse(row("Time Taken").ToString())
row("Delay") = (durationTime - timeTaken).TotalSeconds.ToString()
End Sub)
InvokeCode.xaml (10.9 KB)
Check this please.
I simply just used an Excel scope and loop through.
Hope this useful!
Main.xaml (13.5 KB)
What’s not working? Code giving any error or the output is incorrect or something else?
i need to find total for task duration, time taken, delay and mention delay value is minus mention status column delayed.
To calculate the total for task duration, time taken, and delay while updating the status based on delay values in UiPath, follow these steps:
Steps:
Read the Excel/CSV File:
Use the Read Range activity to read the data from your Excel/CSV file into a DataTable.
Add a Status Column:
Use the Add Data Column activity to add a new column named “Status” to the DataTable.
For Each Row Loop:
Use a For Each Row activity to iterate through each row in the DataTable.
Calculate the Total Task Duration, Time Taken, and Delay:
Inside the loop, sum the values of the “Duration,” “Time Taken,” and “Delay” columns.
Convert the delay to a negative value if it represents a delay.
Example of calculation:
totalDuration = CInt(row(“Duration”))
totalTimeTaken = CInt(row(“Time Taken”))
delay = CInt(row(“Delay”))
Check for Delays and Update Status:
Check if the delay value is negative:
If delay < 0 Then
row(“Status”) = “Delayed”
Else
row(“Status”) = “On Time”
End If
Output Total Values:
Once you’ve iterated through all rows, calculate the total for “Duration,” “Time Taken,” and “Delay” by summing up these values across the rows.
Example for total calculation:
totalDuration = dt.AsEnumerable().Sum(Function(r) CInt(r(“Duration”)))
totalTimeTaken = dt.AsEnumerable().Sum(Function(r) CInt(r(“Time Taken”)))
totalDelay = dt.AsEnumerable().Sum(Function(r) CInt(r(“Delay”)))
Write Back the Data (Optional):
Use Write Range to write the updated DataTable back to the Excel file if needed.