This question already has answers here:
How to SUM duration in Google Sheets?
(5 answers)
Closed 1 year ago.
I have time values above 24 hours in one column and need to calculate a sum, but it's tricky. I tried using this formula
=ARRAYFORMULA(TEXT(SUM(IFERROR(TIMEVALUE(K2:INDIRECT(CONCAT("K", ROW()-1))))), "[hh]:mm"))
the time values are in column K
Also I tried using Query function
=Query({A1:K,{"Duration";ArrayFormula(if(len(K2:K),(hour(K2:K)/24+minute(K2:K)/1440),))}},"Select Sum(Col12)",1)
Result is same for both formulas. Here's the problem. Each 24 hours of each time value resets to 0 when calculating. Let's say the values are 12:00, 12:00, 23:00 then the sum is 47:00 which is OK. but when the values are 12:00, 12:00, 24:00 then 24 turns to 0 and the sum is 24:00. If the values are 12:00, 12:00, 25:00 then then 25 turns to 1 and the sum is 25:00. Same is when the values are 12:00, 12:00 and 49:00 as 49 is 24+24+1 so it turns to 1:00
try:
=ARRAYFORMULA(TEXT(SUM(IFERROR(VALUE(TO_TEXT(INDIRECT("A1:A"&ROW()-1))))), "[h]:mm"))
Related
This question already has answers here:
How to SUM duration in Google Sheets?
(5 answers)
Closed 2 months ago.
This post was edited and submitted for review 2 months ago and failed to reopen the post:
Original close reason(s) were not resolved
I'm making calculations on production cost (in number of resources) and duration.
I have a process that takes 5 minutes. Using the Duration format, I would enter that as 00:05:00.
I want to queue up this process a certain number of times and calculate the total duration. The output should either be something like 16:35:00 or 5 02:15:00. A "d HH.mm.ss" format.
How, in Google Sheets, do I multiply a Duration by an integer to get a total Duration? To be clear, I am not doing a summation of a column of durations. I am taking a duration constant, such as 5 minutes or 25 minutes, and multiplying it by an integer representing the number of times the process will be run, consecutively.
All these attempts resulted in Formula Parse Error:
=(5*00:05:00)
=(112*00:05:00.000)
=(VALUE(C27)*00:05:00)
=MULTIPLY(VALUE(C27),00:05:00.000)
Well, blow me down. I came up with a workaround while I was trying different ways to fail. I assigned 00:05:00 to it's own cell with the Duration format, then referenced that cell in the formula.
I.E. =C27*J7 gives me 9:20:00 when C27 equates to 112 (it's a summation of it's own) and J7 is the cell holding 00:05:00.
Still doesn't give me days when it goes over 24 hours, and I'd rather have the duration value as a constant in the formula, but it's a step forward.
Would something like this work for you?? It's no longer a number, but if it's for expressing the amount in your desired format it may be useful:
=IF(ROUNDDOWN(W2*W3),ROUNDDOWN(W2*W3)&"d "&TEXT(W2*W3-ROUNDDOWN(W2*W3),"hh:mm:ss"),TEXT(W2*W3,"hh:mm:ss"))
Change the cell references, obviously
PS: If you want to have the value as a constant in your formula, you can try to change the cell reference with TIME function within your formula:
In both Excel and Google spreadsheet, DATE are represented in a number start counting from 1899/12/30,
which...
1 is equal to 1 day
1/24 is equal to 1 hour
1/24/60 is equal to 1 minute
1/24/60/60 is equal to 1 second
you can do like:
=TODAY()+1 which gives you tomorrow, or...
=TODAY()+12/24 which gives you "date of today" 12:00:00
and when you are done with the calculations, you can simply use a TEXT() to format the NUMBER back into DATE format, such as:
=TEXT(TODAY()+7 +13/24 +15/24/60,"yyyy-mm-dd hh:mm:ss")
will return the date of a week away from today at 01:15:00 p.m.
This date/time format doesn't requires a full date to work, you can get difference of two time format like this:
=TEXT(1/24/60 - 1/24/60/60,"hh:mm:ss")
since 1/24/60 is 1 min, and 1/24/60/60 is 1 second,
this formula returns 00:00:59, telling you that there is a 59 seconds diff. between 1 min and 1 sec.
I need to filter from B to K IF column A is any time in the last 15 minutes from now AND column J says "Yes"
A has the format Hour-Minute-Second, for example "17:20:59". Lets say now is 18:00:00, I want this formula to return all values from 17:45:00 until now.
For now I did this:
=FILTER(B:K, A:A=TODAY(),J:J="Yes")
I need the same but instead of today, the last 15 minutes.
How can I achieve this?
Now returns the time whereas today does not, just subtract minutes / 1440 because that is how many minutes are in a day:
=FILTER(B:K, A:A>=Now()-15/1440+n(whatthefoxsay()),J:J="Yes")
I want to get an hour ago hour value of current time in google sheets.
For example
TEXT(NOW(),"DDHH")
returns current date+hour value (2500, if its 25th, midnight)
can I get 2423 instead using formula?
just putting -1 works for most of hours but fails at midnight (it returns 2499)
Try using
=TEXT(NOW()-1/24,"DDHH")
In date notation 1 is one day and one hour is 1/24 of a day.
It works for me:
(note that I use ; instead of comma as I have polish settings in my spreadsheet).
Adding -1 at the end of the formula will return 2499 because it will treat it like integer 2500 - 1. Adding -1 after NOW() will return 2400 because it will subtract 1 as 1 day. You can try this formula to subtract an hour.
=TEXT(NOW()-(1/24),"DDHH")
Time started time end Duration
6:02:53 PM 6:11:07 PM 0:08:13
6:11:22 PM 6:20:33 PM 0:09:11
6:20:48 PM 6:32:21 PM 0:11:34
6:32:44 PM 6:39:04 PM 0:06:20
6:39:28 PM 7:00:41 PM 0:21:13
7:01:00 PM 7:09:16 PM 0:08:16
7:09:40 PM 7:16:03 PM 0:06:23
7:16:03 PM 7:24:21 PM 0:08:17
7:24:45 PM 7:30:57 PM 0:06:12
7:31:27 PM 7:37:21 PM 0:05:54
7:37:21 PM 7:44:06 PM 0:06:45
I want sum of all duration entries in x hours x minutes x seconds like i have more then 1000 rows of duration when i try to use =SUM(C2:C100) I am not getting sum of total duration after sum of 24:00:00 24 hours it starts from 00:00:00
for example sum of total duration gets 24:00:00 between range of c1:c8 it will start from 00:00:00 from c9: next range kindly assist me how to overcome this issue
try:
=ARRAYFORMULA(TEXT(SUM(IFERROR(TIMEVALUE(C:C))), "[h]:mm:ss"))
spreadsheet demo
Wherever you put the =SUM(), Select that cell and do Format>Number>More Formats>Custom Number formatting, and put the same formatting that Player0 put in his answer:
What worked for me to resolve a similar problem was a suggestion by user ttarchala in Google Sheets Query multi condition sum of time duration.
I used N() function as he said, and my final formula for the duration is:
=IF(To<>"", N(To-From+(To<From))*24, "")
with To and From being Named ranges for End Time and Start Time respectively.
N() function converts the time delta into a number. Multiplied by 24, this gives the hours in decimal format, such as 2 hours 30 minutes = 2.5 hours.
From there on, there is no problem with using the built-in Sum function to calculate the total duration as a decimal. Such as, the total duration of 27 hrs 10 minutes is shown as 27.16. This sufficed for my purposes.
Time delta is calculated using a formula from https://webapps.stackexchange.com/questions/104829/calculate-time-difference-between-times-past-midnight to take into account past-midnight differences.
And the first condition, To<>"", makes sure the formula is not showing in empty cells. As soon as the End Time is filled into "To" column, the decimal duration is calculated. Then it can be used in the regular Sum function.
This seemed shorter and easier than the formulas suggested above so I am sharing it in the hopes it may help someone else. Using thus formula, I just added up the Sum of time I spent looking for this solution: 3.34 hours :)
It's a formatting problem. You formatted your reply as HH:MM:SS, therefore the number displayed is not showing the date, which would have been incremented by one. If you multiply your sum by 24, and then format the result as a pure number, you will get a number that goes above 24, and will show you the number of hours, and its decimals. If you use those hours in further calculations, the result will be correct.
In cell C1, use the formula
=IF((B1-A1)>=0, B1-A1, 1+B1-A1)
Explanation: the problem is durations that exceed the 24 hour limit, as you say.
Google Sheets has become a bit deceptive here, as it will show the correct duration for the individual time interval, but if you SUM over it, it will actually deduct the value!
A B C
23:39 1:10 1:31
When you SUM then Google Sheets will see the value in cell C1 as if it was the beginning of the same day as the time in A1. So when you in C1 do =B1-A1 then it will register as a negative duration! But it won't show up as that!
In C1 use this formula, =IF((B1-A1)>=0, B1-A1, 1+B1-A1) for individual cells in column C, when you see that cells in column B has exceeded the 24-hour limit once. The duration in C1 should still show 1:31, but now the result when doing SUM over a range of cells in column C, like =SUM(C1:C2), will now show the correct and strictly additive sum. You can safely copy this formula to all cells in column C.
PS: cells in all of the columns can have Automatic or no formatting (which I think defaults to Automatic), if your time inputs look like the above. So you don't need to format all of those cells to Time or Duration. BUT remember to format the SUM cell to Format -> Number -> Duration.
PPS: if you are manually inputting the times (for for instance time tracking), then the easiest way to keep the much simpler =B1-A1 formula is to split the time up into two rows, like this:
A B C
23:39 0:00 0:21
0:00 1:10 1:10
Then the SUM of cells in column C still becomes 1:31.
I am using Google Sheets and am trying to find the largest value for cells that contain a specific year.
Example:
A B
DATE Value
1 jan 1875 4000
1 jan 1880 800
5 feb 1875 3500
6 jun 1875 2500
I have read about the MAXIFS function but am unsure how to apply it in this situation.
MAXIFS(B2:B4;A2:A4;1875) only returns "0" when I want it to return "4000" in B2.
I have tried substituting the "1875" in the formula with "YEAR(1875)" but it doesn't work.
It might be an issue with the dates being before 1900 but I've tried using years after 1900 as well, still it won't work.
Anyone here who knows?
I suggest a query instead of MAXIFS:
=query(A:B,"select max(B) where A contains 1875")