Excel - Plot time slots on a continuous time axis - excel

Let's say we have time slots documented in which a production line was running. In between each product maufactured are time slots in which the machine was idling.
I now want to plot the machine status over time, basically as a boolean value (running vs idling).
I get the machine log and need the chart on the right.
The machining duration will ultimately be logged including seconds and may vary for each product.
The first - and probably biggest - challenge for me is to find a smart way to extract the status from the time stamps. My current first step ist to create a table row for each minute and use the if statement in H4 to check wether article 1 was being manufactured.
IF(AND([#Time]>Machine_log[#Start],[#Time]<Machine_log[#Finish]);;)
However, since the final list will range over 24 hours or more and the number of articles quickly reaches 50 and more, I would love to avoid using nested IFs on this one..
I'm thankfull for any input and open for inspiration :)
Thank you all in advance!
PS: Anyone know how a better way than a scatter chart with two values per X-Value to display the chart as vertical lines/right angles like this?

One option is to add only those points that are necessary to the Status extraction table (which I named "Status"). (I named the Machine log table "Log").
Note: it looks like you are using a semicolon list separator, so you'll need to change the commas in the formulas below to semicolons.
Formula for the Time column:
=IF(ROW()=ROW(Status),MIN(Log[Start])-1/144,IFERROR(INDEX(Log[[Start]:[Finish]],INT((ROW()-ROW(Status)-1)/4)+1,MOD(INT((ROW()-ROW(Status)-1)/2),2)+1),MAX(Log[Finish])+1/144))
Formula for the Production running? column (enter into H4 and fill down):
=IF(SUMPRODUCT(--(Log[[Start]:[Finish]]=[#Time])),IF([#Time]=G3,3-H3,H3),1)
These formulas will pad your plot with 10 minutes of off time on either side.
To answer your question about avoiding two points for each x-value: no, each point on the plot has to have a corresponding data pair.
UPDATE IN RESPONSE TO COMMENT: I failed to mention that the above solution assumes the time data in the Machine log table are in ascending order. This means that if your data span more than one day, they will need to contain a date component or you can get plots where the line crosses back to the beginning. For example, if you have 23:57:00 followed by 00:10:00 with no date component, Excel treats these as 11:57 pm on 1 January 1900 and 12:10 am on 1 January 1900. (To see this, change the format to "General", and you'll see the values that Excel uses to encode date-time aren't in ascending order.) The solution is to enter the dates as "8/16/2020 23:57:00" and "8/17/2020 00:10:00" in the formula bar. If you're copying over from another data source, the date needs to be copied with the time. If the dates and times are in separate columns, your Start and Finish columns would each be a date column plus a time column.

Related

Excel average if function for obtaining hourly data

I have minute data for air temperature and relative humidity (about 930,000 cells) for a building and I am trying to obtain the hourly average using excels "AverageIF" function. Here's the criteria that I have come up with: whenever one hour passes, average the air temperature and relative humidity for that hour. I am having trouble communicating these criteria to excel and any help would be appreciated. I have included a pic of what my data looks like:
the yellow row is me manually adding a row after an hour has passed and calculated the average using the average function.
In the example above I went a bit long winded in the formula to deal with time intervals where there was no data, as that generates a divide by 0 error.
Essentially what I did was setup a summary table to the right. I gave a start and end time for each hour (ASSUMING this is based on a 24 hour clock and not 1 hour from some arbitrary start time)
I used the AVERAGEIFS function as you have two criteria. Everything after a start time and everything before an end time. Only lines that match BOTH criteria are included.
The basic formula looks like this and is based on my example cell J4:
AVERAGEIFS(E$4:E$31,$C$4:$C$31,">="&$H4,$C$4:$C$31,"<="&$I4)
If the date is important, then you would need to add a date column to the table on the right and add a third criteria to the formula above.
In order to deal with divide by zero error and display blank instead of zero so you can distinguish between actual average of 0 and no data and still presenting an error when another type of error comes up I use the following formula in J4:
=IFERROR(AVERAGEIFS(E$4:E$31,$C$4:$C$31,">="&$H4,$C$4:$C$31,"<="&$I4),IF(ERROR.TYPE(AVERAGEIFS($E$4:$E$31,$C$4:$C$31,">="&$H4,$C$4:$C$31,"<="&$I4))=2,"","ERROR"))
The above formulas can be copied down and to the right.

Excel Group rows based on time interval

I have the following excel result:
I want to group the above result in groups based on sessions i.e. if the time gap between two successive timestamps is greater than 5 minutes, it must be a new row.
For example :
I need some formula to achieve this. As I'm fairly new to Excel this is causing to be a major headache for me. Please help me, if anyone knows how to do it or at least point me in a direction.
Thanks a ton !!!
Judging by your screenshot, it appears your timestamps are actually text values. Text by default is usually left aligned where as numbers are right aligned. You seem to have a space at the end of your time stamp suggesting that it is probably left aligned and therefore text. You can test it with the following formula which will return TRUE if its text.
=ISTEXT(P2)
where P2 is one of your time stamps.
CONVERT TIMESTAMPS TO TIME
There are a variety of ways to do this. Some will depend on system settings. Take a look at the following functions as each might be useable depending on your system. The first two are a guarantee, the last two are more dependent on system settings.
DATE
TIME
DATEVALUE
TIMEVALUE
Something important to remember here is that in excel dates are integers counting the days since 1900/01/01 with that date being 1. Time is stored as a decimal and represents fraction/percentage of a day. 24:00:00 is not a valid time in excel though some functions may work with it.
So in order to convert your time stamp in P2 I used the following formula to pull out the date:
=DATE(LEFT(P2,4),MID(P2,FIND("-",P2)+1,2),MID(P2,FIND(" ",P2)-2,2))
Basically it goes into the text and strips out the individual numbers for Year, Month and Day.
To pull out the time, I could have done the same procedure but elected to demonstrate the TIMEVALUE method which is a little more robust than DATEVALUE and not a subjective to system settings as much. With the following formula I stripped out the whole time code (MINUS"UTC"):
=TIMEVALUE(TRIM(MID(P2,FIND(" ",P2)+1,FIND("UTC",P2)-FIND(" ",P2)-1)))
I also made an assumption that you are not mixing and matching UTC with other time zones which means it can be ignored. Now to get DATE and TIME all in one cell, you just need to add the two formulas together to get:
=DATE(LEFT(P2,4),MID(P2,FIND("-",P2)+1,2),MID(P2,FIND(" ",P2)-2,2))+TIMEVALUE(TRIM(MID(P2,FIND(" ",P2)+1,FIND("UTC",P2)-FIND(" ",P2)-1)))
In the example at the end, I placed that formula in Q2 and copied down
DELTA TIME
Since you want to break your groups out based on a time difference between individual entries, I used a helper column to store the time difference. In my example at the end I stored this difference in Column S. The first entry is blank as there is no time before it. I used the following formula in S3 and copied it downward.
=Q3-Q2
I applied the custom formatting of [h]:mm:ss to the cell to get it to display as shown.
FIND GROUP BREAK POINTS
In my example I am using helper column T to hold breakpoint flags. At a minimum, you will have two break points. Your first time entry and your last time entry. To make like simple I simply hard coded my first breakpoint flag in T2 as 1. Stating in T3, Three checks need to be made. If any of them are TRUE then the next flag needs to be added with a value increase by one. the three checks are:
Is this the last entry
Is the next time delta greater than 5 minutes (means end of a group)
Is this time delta greater than 5 minutes (means start of a group)
Based on those three checks I placed the following formula in T3 and copied down:
=IF(OR(S4="",S4>TIME(0,5,0),S3>TIME(0,5,0)),MAX($T$2:T2)+1,"")
Note the $ on the first part of the range for the MAX function. This will lock the start of the range while the formula gets copied down while the end of the range increases accordingly.
Also the row after the last time entry must be blank. IF it is not blank and has a set value in it, change the S4="" to S4="set value".
GENERATE TABLE
There are multiple ways to reference the flags and pull the corresponding times. a couple of formulas you can look into are:
INDEX / MATCH
LOOKUP
In this example I elected to use LOOKUP though I believe INDEX and MATCH are more appropriate and robust. For starters we want to generate a list of ODD number and EVEN numbers. These represent the start and end of the groups and correspond to the flags set in column T. One way to generate ODD and EVEN numbers as you copy down is:
=ROW(A1)*2-1 (ODD)
=ROW(A1)*2 (EVEN)
The next step is to find the generated number in Column T and then pull its corresponding timestamp in Column Q. I did this with the following formula in V2 and copied down.
=LOOKUP(ROW(A1)*2-1,T:T,Q:Q)
And in W2
=LOOKUP(ROW(A1)*2,T:T,Q:Q)

Formatting Existing Excel Cells to Time Format Without Date

I'm working on an excel 2010 sheet where I mark down the date and time an event happens. The date is in one column, and auto formats to 17-Nov when I would type in 11-17 (I was fine with this). The time is in a separate column.
I am trying to find the average time an event occurred, without regard to the date, so I would use =AVERAGE(C1:C10). However, I only receive a date back (like 17-APR).
I did not format the cells before I began to enter in data, and I would simply type in a 3:27pm event as 1527, and no reformatting would happen.
Now, when I attempt to reformat the column to hhmm, all the numbers entered so far turn to 0000. When I try to edit the 0000, it is formatted as 6/13/1906 12:00:00 AM.
What I want to do is have the time formatted as hhmm and not include a date in the cell, and be able to run formulas on it, such as the average time an even occurred.
Summary:
*Currently time is entered simply as ####. I entered 3:27pm as 1527.
*Trying to reformat the time column results in 0000 in all cells in the column that previously had a ####.
*Modifying the 0000 displays as 6/13/1906 12:00:00 AM
*I want to format the time as hhmm so I can simply type in 2357, and have it display as 2357, but understand I mean 11:57pm, and let me take averages.
*Hell, even being able to enter 1547 and have it auto format to 15:47 or 3:47p would be great.
Thanks for reading my question!
An easy way to apply an autoformat (though Excel won't see it as a true "Time") is to go into Format Cells>Custom> and use ##":"##. This will turn 1245 into 12:45. Mind you, this will be a text string so if you copy it to another cell and then apply a time, it will show as 12:00:00. Excel will also not be able to run formulas on it, but it's a quick and dirty way to make it look pretty.
Another option is to have a formula such as =TIME(LEFT(A1,2),RIGHT(A1,2),) where A1 would be replaced with the cell you are actually referencing. This will convert the number to a time that Excel will recognize as a time allowing you to run other functions on it, but requires another column.
If you are entering the times as 4-digit numbers, you'll need to do a calculation to get the hours and minutes, then use the TIME function to get an actual time:-
=TIME(A1/100,MOD(A1,100),0)
Another way is
=LEFT(A1,2)/24+RIGHT(A1,2)/1440
but then you have to format the result as a time.
Excel sees a number like 1547 as approximately 4 years on from 1st January 1900 if you format it as a date, so it will come out as something like 26/3/1904 in UK format or 3/26/1904 in US-style format.
Note that the time function can only give you values up to 23:59:59 (stored as 0.999988426), but the second method will give you a datetime value with one or more days as the whole number part. This can be useful if you want to do calculations on times spanning more than one day.
The above behaviour is because dates and times are stored as real numbers with the whole number part representing days and the decimal part representing fractions of a day (i.e. times). In spite of misleading information from Microsoft here, dates actually start from 31/12/1899 (written as 0/1/1900) with serial number 0 and increment by 1 per day from then on.

Excel - Evaluate multiple cells in a row and create report or display showing lowest to highest

In an Excel 2003 spreadsheet, I have the top row of cells calculating the number of days and hours I have worked on something based on data I put in the cells below for each category. For example I enter the time spent on Programming, Spoken languages, house, piano, guitar...etc. The top cell in each category will keep track of and display how many days and hours I spent as I add the time spent for each category each day. I want to evaluate this top row and then list in a "report" (like a pop up box or another tab or something) in order from least amount of time to the most amount of time. This is so I can see at a glance which category is falling behind and what I need to work on. Can this be done in Excel? VBA? Or do I have to write a program from scratch in C# or Java? Thanks!
VH
Unbelievable... I've been scolded for trying to understand an answer and requested to mark this question answered. I don't see anything to do this and could not find anything that tells you how, so I'm just writing it here. MY QUESTION WAS ANSWERED... But thanks anyway...
Consider the following screenshot:
The chart data is built with formulas in columns H3:I3 and below. The formulas are
H3 =INDEX($B$3:$F$3,MATCH(SMALL($B$2:$F$2,ROW(A1)),$B$2:$F$2,0))
I3 =INDEX($B$2:$F$2,MATCH(SMALL($B$2:$F$2,ROW(A1)),$B$2:$F$2,0))
Copy down and build a horizontal bar chart from the data. If you want to change the order of the source data, use LARGE() instead of SMALL().
Alternative Approach
Instead of recording your data in a matrix, consider recording in a flat table with columns for date, category and time spent. That data can then easily be evaluated in many possible ways without using any formulas at all. The screenshot below shows a pivot table and chart where the data is sorted by time spent.
Edit after inspecting file:
Swap rows 2 and 3. Then you can choose one of the approaches outlined above.
Consider entering the study time as time values. It is not immediately clear if your entry 2.23 means 2 hrs and 23 minutes, or 2 hrs plus 0.23 of an hour, which totals to 2hrs, 13 minutes.
If you are using the first method, then all your sums involving decimals are off. For example, the total for column B is 7.73 as you sum it. Is that meant to be 7 hrs and 73 minutes? That would really be 8 hrs and 13 minutes, no? Or is it meant to be 7 hrs and 43 minutes? You can see how this is confusing. Use the colon to separate hrs and minutes and - hey - you can see human readable time values and don't have to convert minute values into decimals.

Chart or in Excel From List of Timestamps

I have a program that writes the currenct time to excel when a process is called, so I have an excel file with one column of over 5000 timestamps in HH(24):MM:SS format. I'm trying to visualize these over a 24 hour period in order to find a time where the process is least likely to occur. Can anyone get me started?
Thanks
Simply selecting the data in your column and Insert > Charts – Scatter, Scatter with only Markers might suit. The closer the markers to one another (or the shallower the slope) should indicate the process has been called often in a short time interval. ie the quieter periods are when the slope is steep.
If not a very helpful visualisation then maybe count the number of starts over intervals of fixed length (create ‘bins’) and plot a histogram. “a time where the process is least likely to occur” implies that not only start time but duration may be relevant. In which case an an interval of approximately the average duration may be useful.
If you give Excel a column of timestamps in a format it understands, it can map them to a fraction representing how far into the day that timestamp is. For example, if you paste in "12:00:00" and then format that cell as a number, you will get 0.5. Likewise 06:00:00 to 0.25, etc. These numbers can then be plotted on a histogram by following these steps.
Caveat: Only confirmed this works in Excel 2013.

Resources