Find a temperature and work out how long it remained >= this temperature - excel

I have an excel sheet with times in one column and temperatures in another. I'm trying to work out a formula that will find a certain temperature and measure how long it remained at that temperature.
11:25:29 AM 69.3°C
11:26:29 AM 69.6°C
11:27:29 AM 69.8°C
11:28:29 AM 70.0°C
11:29:29 AM 70.2°C
11:35:29 AM 70.8°C
11:36:29 AM 70.3°C
11:37:29 AM 69.5°C
11:38:29 AM 68.5°C
11:39:29 AM 67.5°C
12:39:29 PM 66.3°C
1:39:29 PM 52.1°C
2:39:29 PM 12.1°C
3:39:29 PM 5.0°C
In this example, I would like to find when it hit 70.0°C and how long it stayed above 70.0°C.

This is a bit of a tough problem because you might have multiple occasions where you go above 70 degrees. In that case, do you want the total time spent above 70 in the entire dataset, or do you want the total time spent above 70 consecutively? And then, how are you determining which of these potential multiple nonconsecutive periods you are talking about?
That said, you can try this. If column A is your datetime, and column B is your temp reading, specify another cell as your temperature reference value ($D$1 here), and in column C starting in row 2 do this:
=(A2-A1)*IF(B2>=$D$1,1,0)
and then copy that all the way down. What that does is it calculates the time difference between measurements and then if the temperature at that time is greater than your reference, it multiplies it by 1, otherwise it multiplies by 0. Because a date/time in Excel is really just a number, what you get is an interval of a day between measurements in each cell of column C. In other words, .25 = 6 hours.
Now that you have that data in column C, you are free to further parse it. You can use a simple SUM(C:C) formula in a cell, or you can go back and sum up individual ranges. I hope this helps.

Related

Excel hours worked calculation, based on specific time shifts

I have an excel with working hours in format Starting: 15:30 (A1) and finishing: 01:00 (B1). I would like to calculate the hours that i worked as nightshift (C1). The night shift is between 22:00 and 06:00. So if i work for example 17:00 to 02:15, i should get the number 04:15 as nightahift hours. I i work from 22:00 to 09.15 i should get 8 nightshift hours. I got the time difference with this
""=MOD(B2-A2;1)"" but this gets the whole shift and not the night ones only. Any suggestions?
It seems that this code works for one pair of columns, but i cannot figure out how to sum the results. The excel is seperated into columns, where every date has 2 columns for Starting and Ending shift
=MOD(D4-C4;1)24-(D4<C4)(22-6)-MEDIAN(D424;6;22)+MEDIAN(C424;6;22)
The ideal would be to have a formula to this result
=MOD(D4-C4;1)24-(D4<C4)(22-6)-MEDIAN(D424;6;22)+MEDIAN(C424;6;22)+
MOD(F4-E4;1)24-(F4<E4)(22-6)-MEDIAN(F424;6;22)+MEDIAN(E424;6;22)+
MOD(H4-G4;1)24-(H4<G4)(22-6)-MEDIAN(H424;6;22)+MEDIAN(G424;6;22) etc, but more compact way
Assuming that all input times are relative to 1/0/1900 (only time portion information). Therefore you need to consider when the date refers to the next day (adding 1). The condition for the end date is that if start > end, then the end date refers to the next day (+1). We take into account the above for the solution.
Assuming no excel version constraints as per the tags listed in the question, you can use the following formula in F2:
=LET(start, A2:A5, end, B2:B5, ns, D2, ne, D3+1, eEff, IF(end<start, end+1, end),
CALC, LAMBDA(isStart, MAP(start, eEff, LAMBDA(x,y, IF(y < ns, 0,
MEDIAN(IF(isStart, x, y), ns, ne))))), a, CALC(TRUE), b, CALC(FALSE),b-a)
I created a user LAMBDA function CALC just to avoid repetition of a similar calculation for the actual start (a) and end (b) of the working night interval. As you can see from the formula the night end (ne) has been adjusted to consider the next day. Similarly, we do the adjustment for the end time, calculating the effective end time (eEff) considering the next day when the end time (end) is lower than the start time (start).
We use MEDIAN to identify the actual interval in both cases. Here is the output:
where 0:00 means no time consumed during the night shift. The rest is just to use the correct format: hh:mm in the output to show durations during the night shift.
If you show the input data in numeric format, you can see the times referred to the first valid year in Excel (<= 1):
That is why we need to convert ne and end (in case it represents the next day), but it depends on whether or not you want to consider the next day in your input data. So for row 2 it represents 01:00 of the current day (0.04) so in the formula, we treat it as: 01:00 of the next day (1.04)

Is there a non-VBA way to calculate the average of the sum of two sets of columns?

I'm creating an excel spreadsheet to track when an item is received as well as when a response to the item having been received has been made (ie: my mail was delivered at 1:00pm (item received) but I didn't check the mail until 5:00pm (response to item having been received)).
I need to track both the date and time of the item being received and want to separate these in two separate columns. At the moment this translates to:
Column A: Date item received
Column B: Time item received
Column L: Date item was responded to having been received
Column M: Time item was responded to having been received
In essence I'm looking to run calculations on the response time between when the item is received and when it has been responded to (ie: average response time, number of responses in less than an hour, and even things like the number of responses that took between 2 and 3 hours where Bob was the person who responded).
The per-line pseudo code would look something like:
(Lr + Mr) - (Ar + Br) ' where L,M,A,B are the columns and 'r' is the row number.
An example, with the following data:
1. A B L M
2. 1/5/19 10:00 1/5/19 12:00
3. 1/5/19 21:00 1/6/19 1:00
4. 1/5/19 22:00 1/5/19 23:00
5. 1/6/19 3:00 1/6/19 4:00
The outcome for the average response time would be 2 hours (average(rows 2-5) = average(2, 4, 1, 1) = 2)
The number of items with an average response times would be as follows:
(<=1 hour) = 2
(>1 & <=2) = 2
(>2 & <=3) = 0
(>3) = 1
I don't know (or can find) a function that will perform this and then let me use it within something like a countifs() or averageifs() function.
While I could do this (fairly easily) in VBA, the practical implementation of this spreadsheet limits me to standard Excel. I suspect that sumproduct() will be fundamental to make this work, but I feel that I need something like a sumsum() function (which doesn't exist) and I'm not familiar with sumproduct() to better understand what to even look for to set something like this up.
If you are not so familiar with SUMPRODUCT() or the likes I would suggest one helper column. Like so:
You can see the formula used is:
=((C2+D2)-(A2+B2))
You can probably do all type of calculations on this helper column. Note, column is formatted hh:mm. However, if you want to look into SUMPRODUCT() you could think about these:
Formula in H2:
=SUMPRODUCT(--(ROUND((((A2:A5+B2:B5)-(C2:C5+D2:D5))*-24),2)<=1))
Formula in H3:
=SUMPRODUCT((ROUND((((A2:A5+B2:B5)-(C2:C5+D2:D5))*-24),2)>1)*(ROUND((((A2:A5+B2:B5)-(C2:C5+D2:D5))*-24),2)<=2))
Formula in H4:
=SUMPRODUCT((ROUND((((A2:A5+B2:B5)-(C2:C5+D2:D5))*-24),2)>2)*(ROUND((((A2:A5+B2:B5)-(C2:C5+D2:D5))*-24),2)<3))
Formula in H5:
=SUMPRODUCT(--(ROUND((((A2:A5+B2:B5)-(C2:C5+D2:D5))*-24),2)>3))
The helper column is the easiest approach. It gives you the time differences that you can then easily analyse however you want. Analysis without the helper column is possible, but the approach differs depending on what type of analysis you want to do.
For the example you provided, which is counting the number of time differences grouped into ranges, you would use the FREQUENCY function:
=FREQUENCY(C2:C5+D2:D5-A2:A5-B2:B5,F2:F4)
In F2:F4 (called the "bins"), enter the upper limit of each range you want to count. The Frequency function counts up to and including the first value, then counts from there up to and including the second value, and so on. Enter the bins as times, e.g. 1:00 for 1 hour.
Note that Frequency is an array-entered and an array-returning function. This you means you need to first select the range that will contain all output values, G2:G5 in this example, then enter the function, then press CTRL+SHIFT+ENTER
Also note that Frequency returns an array that is one element larger than the number of bins specified. The extra element is the count of all values greater than the largest bin specified.

Count no. of times: average from timea-timeb is below average from timec-timed the next day

Sorry for the ambiguous title, I have a query which is stumping me in Excel:
I have a range of temperature data, recordings from every minute of every day for 3 months.
I want to find out how many times the average temperature from 20:30-21:30 on each day is lower than the average temperature from 01:00-02:00 the following morning (about 5 hours difference).
If that is difficult to understand here is a "logic formula":
count(averageTemp(dateX(timeA-timeA+1))<(averageTemp(dateY(timeB-timeB+1)))
Here's a sample of the data as a screenshot:
Please help me out, this one has me scratching my head.
Enter this as an array formula (ctrl+shift+enter) and change "122401" to the last row number of your data range:
=SUM(IFERROR(--(AVERAGEIFS(C2:C122401,B2:B122401,"<="&TIMEVALUE("21:30"),B2:B122401,">="&TIMEVALUE("20:30"),A2:A122401,ROW(INDIRECT(A2&":"&A122401)))<AVERAGEIFS(C2:C122401,B2:B122401,"<="&TIMEVALUE("02:00"),B2:B122401,">="&TIMEVALUE("01:00"),A2:A122401,ROW(INDIRECT(A2+1&":"&A122401)))),0))
This assumes that the first set of temperatures from 01:00-02:00 does not have a matching set from 20:30-21:30.
I would input a flag in column D that takes value 1/0 whether the time is in the frame you are interested in.
So input in D2 = IF(OR(AND(B2<21:30,B2>20:30),AND(B2<01:00,B2>02:00))),1,0).
Then I would go in column C and check if in D I got 1, input a simple IF statement to check for the temperature.
Let me know if it works!

Sum of Averages in Excel Pivot Table

I am measuring room utilization (time used/time available) from a data dump. Each row contains the available time for the day and the time used for a particular case.
The image is a simplified version of the data.
If you read the yellow and green highlights (Room 1):
In room 1, there are 200 available minutes on 1/1/2016.
Case 1 took 60 minutes, case 2 took 50 minutes.
There are 500 available minutes on 1/2/2016, and only one case occurred that day, using 350 minutes.
Room 1 utilization = (60 + 50 + 350)/(200 + 500)
The problem with summing the available time is that it double counts the 200 minutes for 1/1/2016, giving: Utilization = (60+50+350)/(200+200+500)
There are hundreds of rows in this data (and there will be multiple data dumps of differing #'s of rows) with multiple cases occurring each day.
I am trying to use a pivot table, but I cannot obtain the 'sum of averages' for a particular room (see image). I am using a macro to pull the numbers out of the grand total column.
Is this possible? Do you see another way to obtain utilization?
(note: there are lots of other columns in the data, like case start, case end, day of week, etc, that are not used in this calculation but are available)
The reason that you're getting 300 for both Average of Available Time columns is because the grand total is a grand total based on the overall average and not a sum of the averages.
Room 1: 200 + 200 + 500 / 3 = 300
Room 2: 300 + 300 + 300 / 3 = 300
I could not comment on the original question, so my solution is based on a few assumptions.
Assumption #1: The data will always be grouped. E.G. All cases in room 1 on a given day will grouped in sequential rows.
Assumption #2: The available time column is a single value for the whole day, there will never be differing available times on the same day.
Solution: Use column E as the Actual Available Time. This column will use a formula to determine if the current row has a unique combination (Date + Room + Available Time) to the previous and if so, the cell will contain that row's available time.
Formula to use in E2:
=IF(AND($A1 = $A2, $B1 = $B2, $C1 = $C2), 0, $C2)
Extend the formula as far down as necessary and then include the new column in your PivotTable data range.
End Result
I created a unique reference by combining columns and then used sumif/countif/countif.
So the formula in column E would be:
=sumif(colB,cellB,ColC)/Countif(colB,cellE)/Countif(colB,cellE)
Doesn't matter if the data is in order or not then.
Extend the formula as far down as necessary and then include the new column in your PivotTable data range.
The easiest method I would recommend is this.
=SUM(H:H)-GETPIVOTDATA("Average of Available Time",$G$3)
The first term sums the H column, and the second term subtracts the grand total value. It is a dynamic solution, and will change to fit the size of the pivot table.
My assumptions are that the Pivot Table was originally placed in cell G3.

Adding/Subtracting Whole numbers from Time

I have tried every which way to format cells to subtract the result from time for instance the formula in the cell = 11(this is 11 minutes) I want to take that result minus 8:00:00 to give me 7:49:00 but it doesn't work the result is ####### no matter how big I make the cell. And if I format the cells with the formula to custom [m]:ss then the value changes.
Sample of the Worksheet:
I want Y2 = X3-W3 in a time format.
So, if A1=11
Then in some other cell, (B1 in this example): =TIME(,A1,)
Then subtract from the cell with 8:00:00. (If it's C1...:)
=C1-B1
That will give you the time you want.
Info: The main thing is that you have to tell Excel that your cell with the "11" in it, is minutes. By using the =TIME(,A1,) you will get the value of: 12:11 am. (If you keep it in Date format.) 12:11 am could also be viewed as: 0 Hours, 11 minutes, 0 seconds. And now that it knows, you should be able to subtract.
Try this:
=TIME(HOUR(X3),MINUTE(X3)-W3,SECOND(X3))
The ######### is because you have a negative time. Becuase Excel reads time as decimals of 24 hours, 8:00:00 is .3333 and if you subtract 11 from that you get -10.6666 and date/time can not be negative.

Resources