Get sum of timespan column

Hello!

I am having trouble getting the sum of a column from my data table.
I have this table:
image
and I want the results to look like this:
image

I want to remove the multiple names and get the sum of the duration column for that specific name. My problem is I’m not sure of the syntax for getting the sum of DURATION/TIMESPAN. I tried converting into double as well but no luck.

I’m currently using this:
image
but it gives me this error:
image

Any assistance would be greatly appreciated.

Hi @mimuhrin

Looking at the error message, it seem you’re using Assign activity to perform this operation.
Assign only allows a single expression that represents the right hand side of a variable assignment. (For instance, any number of method chaining is possible, but that’s about it)

You should use Invoke Code activity to perform the operations.
Pass the value in as argument of In/Out type so that your value is returned in the calling sequence for further use.

Hi, thanks for responding
The method I use works for int and double so I think it’s okay to use, my problem is when it receives a timespan/duration format like “6:00:00” it doesn’t work so I’m looking for a syntax that would work for getting the timespan/duration format

Hi,

Is your data in datatable not double but timespan format? If so, the following sample expression might helps you. Can you apply it to your query?

new TimeSpan(0,0,0,CInt(dt.AsEnumerable.Sum(Function(r) TimeSpan.Parse(r("Duration").ToString).TotalSeconds)))

Note: Return value contains day value if hour is over 24 because of TimeSpan class specification.

Regards,

2 Likes

Hi Yoichi,

It works on my end now. Your code works, thanks!

1 Like

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