+ Reply to Thread
Results 1 to 10 of 10

Formula Finding Peak Period in Time Log

Hybrid View

  1. #1
    Registered User
    Join Date
    10-29-2007
    Posts
    3

    Formula Finding Peak Period in Time Log

    Hello!
    FAR from an experienced Excel user here.
    We have a specific formula objective, which i haven't been able to solve on my own. Perhaps someone here can assist...

    We have time logs of activity, such as you would expect in a security station. Individuals arrive and are timestamped. We are seeking to find the number of users passing during a peak 5-minute period. I have looked at charting the data to look visually for these peak points in order to narrow our focus, but want to be able to calculate same.
    We have columns in our spreadsheet for entries and their timestamps.
    Any thoughts, or directions you might be able to point me in?
    thanks!
    thom

  2. #2
    Forum Contributor
    Join Date
    03-14-2006
    Location
    Pakistan
    Posts
    1,791

    Lightbulb

    It would be better if you post a sample file with some data here in zip format.

  3. #3
    Registered User
    Join Date
    10-29-2007
    Posts
    3
    Here's a small 10 entry sample. Thanks for the assist!

    Column A= Date
    Column B = Time
    Column C= ID

    All we really want to do is be able to identify a peak 5 minute period in each day...
    t
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    10-30-2007
    Posts
    51
    This is an interesting challenge. I'd like to hear what others think but I don't see how you do it without defining discrete time intervals and adding up the number of time stamps in that interval. If you settle on 5 minute intervals starting 1 minute apart, you end up evaluating 1,440 intervals per day (60*24).

    Ex. 8:00:00 to 8:04:59
    8:01:00 to 8:05:59
    8:02:00 to 8:06:59
    etc.

    You calculate the number of stamps between intervals and take the max.

    If you start the intervals 15 seconds apart you'd have 4 times as many to evaluate. And so on.
    Last edited by MickeyGreen; 10-30-2007 at 02:41 PM.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    I think we'd need daddylonglegs for a worksheet function-based solution.

    In the meanwhile, here's a UDF:
    Function Peak(r As Range, dIntvl As Double) As Date
        ' Returns the date (& time) of the busiest interval of length dIntvl
        ' r is assumed as a single-column range containing the
        ' date and time of events in ascending order
        
        Dim iRow As Long, nRow As Long, mRow As Long
        Dim nEvnt As Long, nMax As Long
        Dim rFind As Range
        
        nRow = r.Rows.Count
        
        For iRow = 1 To r.Rows.Count
            Set rFind = r.Offset(iRow - 1).Resize(nRow - iRow + 1)
            nEvnt = WorksheetFunction.Match(r(iRow).Value + dIntvl, rFind, 1)
            If nEvnt > nMax Then
                Peak = r(iRow).Value
                nMax = nEvnt
            End If
            ' quit if no greater max is possible
            If nRow - iRow + 1 < nMax Then Exit For
        Next iRow
    
    End Function
    Example worksheet usage is =Peak(rangeContainingTimes, "0:05")

  6. #6
    Registered User
    Join Date
    10-29-2007
    Posts
    3
    Thanks for your help!
    As an administrator of a forum, I know it's irritating when folks pop in and out, but more so when they don't bother to acknowledge your assistance on the way out... so thanks for giving this a go for me! Happy halloween...

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    I do indeed appreciate it, wrongrobot, thanks.

  8. #8
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,703
    Just saw Ron's post, this works along similar lines.....

    Assuming you look at fixed 5 minute intervals throughout the day,

    00:00:00 to 00:04:59
    00:05:00 to 00:09:59

    and so on, i.e. 288 periods per day

    You could do the following:

    Assuming a sightly larger dataset with dates in A3:A1200 and times in B3:B1200 then for a specific date in E3 this formula will give you the maximum number of occurrences within any of those 5 minute periods:

    =MAX(FREQUENCY(IF(A$3:A$1200=E3,INT(B$3:B$1200*288)+1),ROW(INDIRECT("1:287"))))

    confirmed with CTRL+SHIFT+ENTER

    and, assuming the above formula in G3 this formula will give the start of the time period

    =(MATCH(G3,FREQUENCY(IF(A$3:A$1200=E3,INT(B$3:B$1200*288)+1),ROW(INDIRECT("1:287"))),0)-1)/288

    also confirmed with CTRL+SHIFT+ENTER

    see attached
    Attached Files Attached Files

  9. #9
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Formula Finding Peak Period in Time Log

    Sorry for being late to this post.....but here's a possible formula solution:

    With
    B1:B50 containing Times
    
    and
    E1: 1st_Period_End_Time
    E2: 12:01:00 AM
    
    The below formulas check each 1-minute interval, 
    beginning with the minute ending 12:01:00 AM, 
    for a 24 hour period.
    
    F1: Max_Interval_Count
    F2: =MAX(FREQUENCY($B$3:$B$50,E2+TIME(0,ROW($A$1:$A$1440)-1,0)))
    
    G1: Interval_Ending
    (ARRAY FORMULA...Committed with Ctrl+Shift+Enter, instead of just Enter)
    G2: =INDEX(E2+TIME(0,ROW($A$1:$A$1440)-1,0),MATCH(MAX(FREQUENCY($B$3:$B$50,E2+TIME(0,ROW($A$1:$A$1440)-1,0))),FREQUENCY($B$3:$B$50,E2+TIME(0,ROW($A$1:$A$1440)-1,0)),0))
    Does that help?
    Post back if you have more questions.
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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