I have a table that I need to find a total duration of attributes.
Name | Duration |
ABCDEFG | 00:00:11 |
ABCDEFG | 00:10:00 |
ABCDEFG | 00:01:00 |
How do I calculate the Duration and put the total in a new field?
Dave - I know this tool may not be what you're looking for, but Summary Statistics (Analysis), would provide a sum of the Duration values BUT it creates a new output table in your geodatabase vs. in the existing feature class table. You could use a Join of the output table to the feature class table though if that would suffice.
That looks like the path to go down but I keep getting this error when I try to use Sum for statistic type.
ERROR 000315 Field Duration only supports statistic types MIN, MAX, MEAN, COUNT, FIRST, LAST, UNIQUE.
Is duration a string? You'd be best creating a new 'seconds' field and doing a field calculate using python.
Not tested it at all but something along the lines of : (I know it would be less verbose as a code block)
(float(duration.split(":")[0]) * 3600) + (float(duration.split(":")[1]) * 60) +(float(duration.split(":")[2]))
Something along the lines of this? Duration is the new field and SUM_Total_Seconds is the seconds field
Sum_Total_Seconds = [f.type for f in arcpy.ListFields(SUM_Total_Seconds) if f.name == sDep][0]
arcpy.management.CalculateField("mStatistics", "Duration", "!Duration!", "PYTHON3", '(float(SUM_Total_Seconds.split(":")[0]) * 3600) + (float(SUM_Total_Seconds.split(":")[1]) * 60) +(float(SUM_Total_Seconds.split(":")[2]))', "TEXT", "NO_ENFORCE_DOMAINS")
I keep getting an error when I try this:
ERROR 002717: Invalid Arcade expression, Arcade error: Close parenthesis expected, Script line: 1
But I don't see where you'd close the parenthesis?
Change your expression type to Python
I get: ERROR 000539: Traceback (most recent call last):
File "<expression>", line 1, in <module>
AttributeError: 'float' object has no attribute 'split'
You're confusing the fields in the tool. Field Name (existing or new) = the new field you want to create (SUM_total_seconds)
you need to use !Duration! in the script.
at the moment you're trying to use split on a value which doesn't exist and also the wrong field type, and then populate a float into a string field which is all wrong.
Best to just create a new field of type float, then use field calculator as it will be simpler.