Help with SUM function with Duration of Time
Hello all,
I have been reading through the forum this morning on how to work around time duration in SS. I used the trusty Travis/Ajayi "formula from hell" to get an actual calculation! yeah!!!
My problem is.... trying to SUM the duration column. I have attached a screenshot. I usually use excel... and am not find SS very user friendly. any help is greatly appreciated!
Comments
-
unless overwritten, if the items in the cell are left aligned, they are understood as text, if they are right aligned they are understood as numbers, the same as excel. Wrap your entire formula in the duration column in Value() then a regular sum will work.
-
L@123,
Thank you for the reply!!
Here is the formula I tweaked from the Travis/Ajayi formula:
=IFERROR(INT((((IF(LEFT([Finish Time]2, FIND(":", [Finish Time]2) - 1) = "12", IF(OR(FIND("a", [Finish Time]2) > 0, FIND("p", [Finish Time]2) > 0), 0, 12), VALUE(LEFT([Finish Time]2, FIND(":", [Finish Time]2) - 1))) + IF(FIND("p", [Finish Time]2) > 0, 12)) * 60 + VALUE(MID([Finish Time]2, FIND(":", [Finish Time]2) + 1, 2))) - ((IF(LEFT([Start Time]2, FIND(":", [Start Time]2) - 1) = "12", IF(OR(FIND("a", [Start Time]2) > 0, FIND("p", [Start Time]2) > 0), 0, 12), VALUE(LEFT([Start Time]2, FIND(":", [Start Time]2) - 1))) + IF(FIND("p", [Start Time]2) > 0, 12)) * 60 + VALUE(MID([Start Time]2, FIND(":", [Start Time]2) + 1, 2)))) / 60) + ":" + IF(((((IF(LEFT([Finish Time]2, FIND(":", [Finish Time]2) - 1) = "12", IF(OR(FIND("a", [Finish Time]2) > 0, FIND("p", [Finish Time]2) > 0), 0, 12), VALUE(LEFT([Finish Time]2, FIND(":", [Finish Time]2) - 1))) + IF(FIND("p", [Finish Time]2) > 0, 12)) * 60 + VALUE(MID([Finish Time]2, FIND(":", [Finish Time]2) + 1, 2))) - ((IF(LEFT([Start Time]2, FIND(":", [Start Time]2) - 1) = "12", IF(OR(FIND("a", [Start Time]2) > 0, FIND("p", [Start Time]2) > 0), 0, 12), VALUE(LEFT([Start Time]2, FIND(":", [Start Time]2) - 1))) + IF(FIND("p", [Start Time]2) > 0, 12)) * 60 + VALUE(MID([Start Time]2, FIND(":", [Start Time]2) + 1, 2)))) - INT((((IF(LEFT([Finish Time]2, FIND(":", [Finish Time]2) - 1) = "12", IF(OR(FIND("a", [Finish Time]2) > 0, FIND("p", [Finish Time]2) > 0), 0, 12), VALUE(LEFT([Finish Time]2, FIND(":", [Finish Time]2) - 1))) + IF(FIND("p", [Finish Time]2) > 0, 12)) * 60 + VALUE(MID([Finish Time]2, FIND(":", [Finish Time]2) + 1, 2))) - ((IF(LEFT([Start Time]2, FIND(":", [Start Time]2) - 1) = "12", IF(OR(FIND("a", [Start Time]2) > 0, FIND("p", [Start Time]2) > 0), 0, 12), VALUE(LEFT([Start Time]2, FIND(":", [Start Time]2) - 1))) + IF(FIND("p", [Start Time]2) > 0, 12)) * 60 + VALUE(MID([Start Time]2, FIND(":", [Start Time]2) + 1, 2)))) / 60) * 60) < 10, "0") + ((((IF(LEFT([Finish Time]2, FIND(":", [Finish Time]2) - 1) = "12", IF(OR(FIND("a", [Finish Time]2) > 0, FIND("p", [Finish Time]2) > 0), 0, 12), VALUE(LEFT([Finish Time]2, FIND(":", [Finish Time]2) - 1))) + IF(FIND("p", [Finish Time]2) > 0, 12)) * 60 + VALUE(MID([Finish Time]2, FIND(":", [Finish Time]2) + 1, 2))) - ((IF(LEFT([Start Time]2, FIND(":", [Start Time]2) - 1) = "12", IF(OR(FIND("a", [Start Time]2) > 0, FIND("p", [Start Time]2) > 0), 0, 12), VALUE(LEFT([Start Time]2, FIND(":", [Start Time]2) - 1))) + IF(FIND("p", [Start Time]2) > 0, 12)) * 60 + VALUE(MID([Start Time]2, FIND(":", [Start Time]2) + 1, 2)))) - INT((((IF(LEFT([Finish Time]2, FIND(":", [Finish Time]2) - 1) = "12", IF(OR(FIND("a", [Finish Time]2) > 0, FIND("p", [Finish Time]2) > 0), 0, 12), VALUE(LEFT([Finish Time]2, FIND(":", [Finish Time]2) - 1))) + IF(FIND("p", [Finish Time]2) > 0, 12)) * 60 + VALUE(MID([Finish Time]2, FIND(":", [Finish Time]2) + 1, 2))) - ((IF(LEFT([Start Time]2, FIND(":", [Start Time]2) - 1) = "12", IF(OR(FIND("a", [Start Time]2) > 0, FIND("p", [Start Time]2) > 0), 0, 12), VALUE(LEFT([Start Time]2, FIND(":", [Start Time]2) - 1))) + IF(FIND("p", [Start Time]2) > 0, 12)) * 60 + VALUE(MID([Start Time]2, FIND(":", [Start Time]2) + 1, 2)))) / 60) * 60), 0)
If I have read it correctly, there is code in there to format as a number. Am I wrong?
-
Could you explain "wrap the entire formula" ? If I read the code correctly, I am changing the data from text to num throughout the formula with the VALUE command. Here is the formula I am using....
=IFERROR(INT((((IF(LEFT([Finish Time]2, FIND(":", [Finish Time]2) - 1) = "12", IF(OR(FIND("a", [Finish Time]2) > 0, FIND("p", [Finish Time]2) > 0), 0, 12), VALUE(LEFT([Finish Time]2, FIND(":", [Finish Time]2) - 1))) + IF(FIND("p", [Finish Time]2) > 0, 12)) * 60 + VALUE(MID([Finish Time]2, FIND(":", [Finish Time]2) + 1, 2))) - ((IF(LEFT([Start Time]2, FIND(":", [Start Time]2) - 1) = "12", IF(OR(FIND("a", [Start Time]2) > 0, FIND("p", [Start Time]2) > 0), 0, 12), VALUE(LEFT([Start Time]2, FIND(":", [Start Time]2) - 1))) + IF(FIND("p", [Start Time]2) > 0, 12)) * 60 + VALUE(MID([Start Time]2, FIND(":", [Start Time]2) + 1, 2)))) / 60) + ":" + IF(((((IF(LEFT([Finish Time]2, FIND(":", [Finish Time]2) - 1) = "12", IF(OR(FIND("a", [Finish Time]2) > 0, FIND("p", [Finish Time]2) > 0), 0, 12), VALUE(LEFT([Finish Time]2, FIND(":", [Finish Time]2) - 1))) + IF(FIND("p", [Finish Time]2) > 0, 12)) * 60 + VALUE(MID([Finish Time]2, FIND(":", [Finish Time]2) + 1, 2))) - ((IF(LEFT([Start Time]2, FIND(":", [Start Time]2) - 1) = "12", IF(OR(FIND("a", [Start Time]2) > 0, FIND("p", [Start Time]2) > 0), 0, 12), VALUE(LEFT([Start Time]2, FIND(":", [Start Time]2) - 1))) + IF(FIND("p", [Start Time]2) > 0, 12)) * 60 + VALUE(MID([Start Time]2, FIND(":", [Start Time]2) + 1, 2)))) - INT((((IF(LEFT([Finish Time]2, FIND(":", [Finish Time]2) - 1) = "12", IF(OR(FIND("a", [Finish Time]2) > 0, FIND("p", [Finish Time]2) > 0), 0, 12), VALUE(LEFT([Finish Time]2, FIND(":", [Finish Time]2) - 1))) + IF(FIND("p", [Finish Time]2) > 0, 12)) * 60 + VALUE(MID([Finish Time]2, FIND(":", [Finish Time]2) + 1, 2))) - ((IF(LEFT([Start Time]2, FIND(":", [Start Time]2) - 1) = "12", IF(OR(FIND("a", [Start Time]2) > 0, FIND("p", [Start Time]2) > 0), 0, 12), VALUE(LEFT([Start Time]2, FIND(":", [Start Time]2) - 1))) + IF(FIND("p", [Start Time]2) > 0, 12)) * 60 + VALUE(MID([Start Time]2, FIND(":", [Start Time]2) + 1, 2)))) / 60) * 60) < 10, "0") + ((((IF(LEFT([Finish Time]2, FIND(":", [Finish Time]2) - 1) = "12", IF(OR(FIND("a", [Finish Time]2) > 0, FIND("p", [Finish Time]2) > 0), 0, 12<
-
The problem is that you are trying to SUM "text". You cannot add :. You will need to separate the hours from the minutes, sum them separately, then merge them back together taking into account for a total of minutes over 60 adding in extra hours.
This is one of the reasons that I like to spread things out using helper columns instead of using a monster formula. If you had used helper columns for the calculations you would have already parsed out the hours from the minutes and you could do the calculations from those columns. As it is, you will need to add a helper column or two.
I would suggest two. Hours and Minutes.
In the Minutes column, it would be a simple
=VALUE(RIGHT(DURATION@row, 2))
In the Hours column you would use
=VALUE(LEFT(DURATION@row, FIND(":", DURATION@row) - 1))
You would then sum the two columns separately. To account for the minutes adding on extra hours, you would want to use something along the lines of
=(SUM(Minutes:Minutes) / 60) - INT(SUM(Minutes:Minutes) / 60)
for the Minutes and then for the hours you would use something like...
=SUM(Hours:Hours) + INT(SUM(Minutes:Minutes) / 60)
-
Also... That Monster formula you used can be simplified to save 773 characters.
Your current formula is 3,179 characters long which is awfully close to the limit of 4,000 characters per cell. If your column names were to be changed to something just a little bit longer and then get into the double and triple digit row references, you could exceed that VERY quickly.
The below formula will calculate time differences assuming the times are within the same day and accounting for am and pm in only 2,406 characters. This will give you a little more wiggle room, and having 20 less cell references means that it will expand in size a lot slower as well.
.
=IF((VALUE(MID([Finish Time]2, FIND(":", [Finish Time]2) + 1, 2))) - (VALUE(MID([Start Time]2, FIND(":", [Start Time]2) + 1, 2))) < 0, (VALUE(LEFT([Finish Time]2, FIND(":", [Finish Time]2) - 1)) + IF(AND(FIND("a", [Finish Time]2) > 0, VALUE(LEFT([Finish Time]2, FIND(":", [Finish Time]2) - 1)) = 12), 12, IF(FIND("a", [Finish Time]2) > 0, 0, IF(AND(FIND("p", [Finish Time]2) > 0, VALUE(LEFT([Finish Time]2, FIND(":", [Finish Time]2) - 1)) = 12), 0, 12)))) - (VALUE(LEFT([Start Time]2, FIND(":", [Start Time]2) - 1)) + IF(AND(FIND("a", [Start Time]2) > 0, VALUE(LEFT([Start Time]2, FIND(":", [Start Time]2) - 1)) = 12), -12, IF(FIND("a", [Start Time]2) > 0, 0, 12))) - 1, (VALUE(LEFT([Finish Time]2, FIND(":", [Finish Time]2) - 1)) + IF(AND(FIND("a", [Finish Time]2) > 0, VALUE(LEFT([Finish Time]2, FIND(":", [Finish Time]2) - 1)) = 12), 12, IF(FIND("a", [Finish Time]2) > 0, 0, IF(AND(FIND("p", [Finish Time]2) > 0, VALUE(LEFT([Finish Time]2, FIND(":", [Finish Time]2) - 1)) = 12), 0, 12)))) - (VALUE(LEFT([Start Time]2, FIND(":", [Start Time]2) - 1)) + IF(AND(FIND("a", [Start Time]2) > 0, VALUE(LEFT([Start Time]2, FIND(":", [Start Time]2) - 1)) = 12), -12, IF(FIND("a", [Start Time]2) > 0, 0, 12)))) + ":" + IF(IF((VALUE(MID([Finish Time]2, FIND(":", [Finish Time]2) + 1, 2))) - (VALUE(MID([Start Time]2, FIND(":", [Start Time]2) + 1, 2))) < 0, 60 + (VALUE(MID([Finish Time]2, FIND(":", [Finish Time]2) + 1, 2))) - (VALUE(MID([Start Time]2, FIND(":", [Start Time]2) + 1, 2))), (VALUE(MID([Finish Time]2, FIND(":", [Finish Time]2) + 1, 2))) - (VALUE(MID([Start Time]2, FIND(":", [Start Time]2) + 1, 2)))) < 10, "0" + IF((VALUE(MID([Finish Time]2, FIND(":", [Finish Time]2) + 1, 2))) - (VALUE(MID([Start Time]2, FIND(":", [Start Time]2) + 1, 2))) < 0, 60 + (VALUE(MID([Finish Time]2, FIND(":", [Finish Time]2) + 1, 2))) - (VALUE(MID([Start Time]2, FIND(":", [Start Time]2) + 1, 2))), (VALUE(MID([Finish Time]2, FIND(":", [Finish Time]2) + 1, 2))) - (VALUE(MID([Start Time]2, FIND(":", [Start Time]2) + 1, 2)))), IF((VALUE(MID([Finish Time]2, FIND(":", [Finish Time]2) + 1, 2))) - (VALUE(MID([Start Time]2<span
-
i'm going back to excel. It's insane to parse everything out just to add back together. Maybe in their next update there will be an option for number or text not number/text
-
I see this for calculating Minutes/Hours (thank you Paul Newcome!). What would this look like for DAYS?
In the Minutes column, it would be a simple
=VALUE(RIGHT(DURATION@row, 2))
In the Hours column you would use
=VALUE(LEFT(DURATION@row, FIND(":", DURATION@row) - 1))
Categories
- All Categories
- 14 Welcome to the Community
- Smartsheet Customer Resources
- 63.9K Get Help
- 410 Global Discussions
- 220 Industry Talk
- 457 Announcements
- 4.8K Ideas & Feature Requests
- 143 Brandfolder
- 136 Just for fun
- 57 Community Job Board
- 459 Show & Tell
- 31 Member Spotlight
- 1 SmartStories
- 298 Events
- 37 Webinars
- 7.3K Forum Archives