+ Reply to Thread
Results 1 to 27 of 27

Binning by Hour of Day

  1. #1
    Registered User
    Join Date
    07-08-2015
    Location
    Barrie
    MS-Off Ver
    Windows 2013
    Posts
    11

    Binning by Hour of Day

    Here's what my data looks like

    Status | DOW | HOD | Seconds Spent

    AD | 4 | 5 | 1200
    TS | 4 | 5 | 10560
    AD | 4 | 6 | 2600

    What I need to do is create a matrix, day of week in the columns, hour of day in the rows, total seconds spent on each status as values (1 matrix per status code). Easy enough with a pivot but the problem is when total seconds exceeds an hour (3600 seconds). For instance, if a status starts at 10:30am and lasts 2 hours, it falls under 3 HOD bins. How can I solve this?

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,418

    Re: Binning by Hour of Day

    Well, if your example data is representative of your real data, you only have hour of the day, so you don't know if a status starts at 10:00, 10:30 or 10:59.

    Or is your data a bit more complicated than your example?

    It would be better, anyway, to post a sample workbook - the FAQ describes how to.

    Pete

  3. #3
    Registered User
    Join Date
    07-08-2015
    Location
    Barrie
    MS-Off Ver
    Windows 2013
    Posts
    11

    Re: Binning by Hour of Day

    Thanks, Pete_UK. You're right, I did a horrid job explaining the data.

    Here is a sample. Thanks for letting me know I can do that. (new here!)

    Example.xlsx

  4. #4
    Valued Forum Contributor
    Join Date
    09-17-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    Excel 2007
    Posts
    454

    Re: Binning by Hour of Day

    This is just one approach to split the time spans into multiple HOD bins.

    time_bins.xlsx

  5. #5
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Binning by Hour of Day

    Maybe this will be of help. I combined the Start Date with the Start Time and combined the End Date and End Time. Then just substracted the start date and time from the end date and time. The seconds are calculated by taking that difference and multiplying by 3600 and 24. That is 3600 seconds per hour and 24 for the number of hours in a day. 1 in Excel time is 1 day so hours, minutes and seconds are decimal fractions of 1 day.

    I separated the values by status and also produced a pivot table that has a "Slicer" that filters by status. You can click in the Pivot table and Group By and choose Hours. Your example doesn't have enough data to really show the grouping by hours.
    Attached Files Attached Files
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  6. #6
    Registered User
    Join Date
    07-08-2015
    Location
    Barrie
    MS-Off Ver
    Windows 2013
    Posts
    11

    Re: Binning by Hour of Day

    cyiangou- thank you very much, this approach will work quite well.

    newdoverman- thank you, i think i see where you were going with this and will try it with more data. p.s. if you were wondering why some of my seconds calculations were doubled, it's because some "statuses" apply twice. I removed the multiplier column from the sample data without realizing this would make it confusing.

  7. #7
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Binning by Hour of Day

    It should be easy to re-apply the multiplier and have everything work.

    If you combine the Date and time into one entry, the calculations with time are simplified. cyiangou has supplied you with a nice formula for the horizontal arrangement that you currently have.

    Are you extracting the date and time from the first two columns with a formula or are you doing that manually?

  8. #8
    Registered User
    Join Date
    07-08-2015
    Location
    Barrie
    MS-Off Ver
    Windows 2013
    Posts
    11

    Re: Binning by Hour of Day

    Thanks, good tip about combining the date and time. Hadn't done that and it will simplify the calculations that straddle midnight. About 50,000 rows so you saved me some upcoming googling!

    I'm extracting date and time with =DATE(MID(.....),...) but the sample was a paste values job.

  9. #9
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Binning by Hour of Day

    I was concerned that you were manually extracting the values. Good, you have that under control.

    Good luck.

  10. #10
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Binning by Hour of Day

    Just filling in time, I created a formula to extract the Date, Time, Hours, Minutes and Seconds from the values in column A just in case you are doing it in two steps. The same formula can be used to extract the end times from column B with a change of cell references from A to B.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Format as dd/mm/yyyy h:mm:ss AM/PM

  11. #11
    Registered User
    Join Date
    07-08-2015
    Location
    Barrie
    MS-Off Ver
    Windows 2013
    Posts
    11

    Re: Binning by Hour of Day

    Thanks, ndm, that's quite helpful.

    I thought this was solved but still having issues! What I need to do is create a heatmap of this data by DOW and HOD, sum of seconds (sometimes rate of statues compared to total) as the values.

    The problem with the current solution is that when a status goes over midnight, it loops around and the remainder is added to 1am, 2am etc. but on the same DOW. For instance, if a 3 hour status begins at 11pm on thursday, i need 1 hour to bin on thursday and 2 on friday.

    Any ideas?

  12. #12
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Binning by Hour of Day

    I don't know how you are calculating DOW and HOD or even what they mean. I have figured out how to split the time of a period that spans midnight. How you want to use this, I don't know for sure.

    What I used in the table was to add two new columns. The first new column is for shifts that start before midnight but doesn't have a finish the same day and calculates the time to midnight. The other column is for periods that start before midnight and finish the next day and calculates the time after midnight. I have only updated the Table and the Pivot Table.
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    07-08-2015
    Location
    Barrie
    MS-Off Ver
    Windows 2013
    Posts
    11

    Re: Binning by Hour of Day

    Thanks, ndm. So they are hour of day (HOD) and day of week (DOW), calculating them with =WEEKDAY and =HOUR formulas.

    I think there's been some confusion! The statuses are not shifts, they are statuses of people who are on a shift. I've uploaded an example that may better illustrate what I'm after.
    Attached Files Attached Files

  14. #14
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Binning by Hour of Day

    I am "chasing my tail" on this one. I solve part and something else goes wrong until I'm back where I started. I'm going to give it a rest. Maybe tomorrow I will get a better handle on this. MSG #4 seems to be the best way of going about this....can't think of anything better at the moment.

  15. #15
    Registered User
    Join Date
    07-08-2015
    Location
    Barrie
    MS-Off Ver
    Windows 2013
    Posts
    11

    Re: Binning by Hour of Day

    Appreciate the help nonetheless! Only thing message #4 is lacking is the ability to put after-midnight time into the next day's bin (for midnight-straddling statuses).

  16. #16
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Binning by Hour of Day

    That is the problem .... midnight....grrrrrrrr!

    A bigger sample of data would help. The example data only covers a few hours on one day.

  17. #17
    Valued Forum Contributor
    Join Date
    09-17-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    Excel 2007
    Posts
    454

    Re: Binning by Hour of Day

    Glad you find that method useful. I've tweaked it a bit, and should now handle midnight rollover.

    time_bins_2.xlsx

    To test, change B1 to 2014/01/02.

  18. #18
    Valued Forum Contributor
    Join Date
    09-17-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    Excel 2007
    Posts
    454

    Re: Binning by Hour of Day

    FrankTO, what is the maximum span of time that will be contained in one set of source data at a time. ie. Is it a one week view, a one month view, year?

  19. #19
    Registered User
    Join Date
    07-08-2015
    Location
    Barrie
    MS-Off Ver
    Windows 2013
    Posts
    11

    Re: Binning by Hour of Day

    Cyiangou, mostly quarterly, one year maximum.

  20. #20
    Valued Forum Contributor
    Join Date
    09-17-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    Excel 2007
    Posts
    454

    Re: Binning by Hour of Day

    I don't see an easy way to handle such a large span simultaneously using my method (without having as many columns as there are hours in a quarter). However you could loop this, outputting one day stats at a time, and then using a pivot table on the resulting data.

  21. #21
    Valued Forum Contributor
    Join Date
    09-17-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    Excel 2007
    Posts
    454

    Re: Binning by Hour of Day

    I think this is pretty much a complete solution for you, if I read your OP correctly:

    time_bins_3.xlsm

    See all 3 sheets

    EDIT: Tweaking example
    Last edited by cyiangou; 07-30-2015 at 04:11 AM.

  22. #22
    Registered User
    Join Date
    07-08-2015
    Location
    Barrie
    MS-Off Ver
    Windows 2013
    Posts
    11

    Re: Binning by Hour of Day

    Excellent! Will take a closer look this afternoon, but at first glance this seems to be doing everything I need.

  23. #23
    Registered User
    Join Date
    06-06-2015
    Location
    Pakistan
    MS-Off Ver
    2013 Professional
    Posts
    13

  24. #24
    Registered User
    Join Date
    07-08-2015
    Location
    Barrie
    MS-Off Ver
    Windows 2013
    Posts
    11

    Re: Binning by Hour of Day

    Cyiangou- Your solution looks like exactly what I need! But, when I plug all my data for the year into it (~40,000 rows) and run the macro, it gets stuck around line 500. I edited the macro date range to include 1/1/14-31/12/14 and I made sure everything was working properly on the "Source" sheet. It's just only copies the first 500 lines when I run it.

    UPDATE: Found the "calcdata" reference in name manager and changed it to include all cells!
    Last edited by FrankTO; 07-31-2015 at 07:06 PM.

  25. #25
    Valued Forum Contributor
    Join Date
    09-17-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    Excel 2007
    Posts
    454

    Re: Binning by Hour of Day

    Excellent. Is is fully working now? Glad to have helped. If you liked this answer, please consider clicking the 'Add reputation' star to the left.

  26. #26
    Registered User
    Join Date
    07-08-2015
    Location
    Barrie
    MS-Off Ver
    Windows 2013
    Posts
    11

    Re: Binning by Hour of Day

    Fully working now. Thanks for putting it together. Appreciate it! Reputation added.

  27. #27
    Valued Forum Contributor
    Join Date
    09-17-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    Excel 2007
    Posts
    454

    Re: Binning by Hour of Day

    Ta very much!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Is there a binning function for data sets?
    By Danja in forum Excel General
    Replies: 4
    Last Post: 08-12-2014, 11:35 PM
  2. [SOLVED] Binning for random numbers
    By jsmithy713 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-06-2014, 09:44 AM
  3. [SOLVED] Binning Time Stamped Data into Intervals
    By pickslides in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-29-2012, 05:48 PM
  4. Using Count/Frequency/Binning to sort data
    By Jarvice in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-14-2012, 06:28 AM
  5. Binning X-Axis Data
    By dluckz77 in forum Excel General
    Replies: 0
    Last Post: 01-30-2012, 09:44 PM
  6. Binning Data Over Numerical Intervals
    By Adam1 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 11-08-2011, 10:00 PM
  7. pivot table rows by number binning
    By shanec26 in forum Excel General
    Replies: 1
    Last Post: 04-03-2009, 04:32 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1