+ Reply to Thread
Results 1 to 9 of 9

Calculating difference between two times through a column of data

  1. #1
    Registered User
    Join Date
    08-21-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2003
    Posts
    4

    Question Calculating difference between two times through a column of data

    Hi, has anyone come across a problem like this before, I could use your advice?

    It will be easier to explain in an example:

    A B
    Time (hh:mm:ss) Digital
    1 10:03:00 0
    2 10:03:01 0
    3 10:03:02 1
    4 10:03:03 1
    5 10:03:04 1
    6 10:03:05 0
    7 10:03:06 0
    8 10:03:07 1
    9 10:03:08 1
    10 10:03:09 0
    11 10:03:10 1
    etc......

    From the data above I am searching for the duration of when the digital column says '1', i.e my function = A5-A3 which would output 2 secs or 00:00:03 & likewise A9-A8.

    The problem I have is that the digital signal is staggered and does not always have the same frequency. I have over 6848 lines of time to check so to do this manually would take me all day.

    Hopefully I have explained my problem and someone has an idea on how to solve this?

    Cheers,
    Going_loco

  2. #2
    Valued Forum Contributor
    Join Date
    09-15-2011
    Location
    Chennai, India
    MS-Off Ver
    Excel 2010
    Posts
    436

    Re: Calculating difference between two times through a column of data

    I have counted all the '1'.

    Please confirm if it is a right resolution.

    =SUMPRODUCT(--((RIGHT($A$2:$A$12,1)+0)=1))
    Please click 'Add reputation', if my answer helped you.

  3. #3
    Registered User
    Join Date
    08-21-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Calculating difference between two times through a column of data

    Hi ramananhrm,

    I tried your formula and it just seems to output 1, do I need to modify it in any way?

    FYI I need to calculate the duration everytime the digital value is 1.

    For example in column C I would have a collection of the time differences each time I have a value of 1 and ignore the zeros.

    Thanks for your help.

    Going_loco


    Quote Originally Posted by ramananhrm View Post
    I have counted all the '1'.

    Please confirm if it is a right resolution.

    =SUMPRODUCT(--((RIGHT($A$2:$A$12,1)+0)=1))

  4. #4
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Calculating difference between two times through a column of data

    Hi,

    So could you just add in your desired results to the table you originally posted? Even better, put it in a spreadsheet?

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  5. #5
    Registered User
    Join Date
    08-21-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Calculating difference between two times through a column of data

    Hi XOR LX ,

    Good idea, hopefully I attached the spreadsheet correctly.

    You'll see in column C I simply subtracted the time when column B outputs 1 from the last time column B says 1 and get a difference in time. I did a couple of the first instance and you'll see straight away that the duration between 1's is staggered and the length of time 1 appears is random.

    Actually now that I think of it, it would be helpful to know what the duration of the zeros was too.

    Cheers,
    Going_loco
    Attached Files Attached Files

  6. #6
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Calculating difference between two times through a column of data

    Hi,

    I had to put a 1 in place of Digital in cell B1 to make the first count work, but try this array formula (confirm with CTRL+SHIFT+ENTER, not just ENTER - Google if you're not sure) in C2 and copy down as required:

    =IF(B2=B3,"",A2-INDEX($A$2:$A$6837,ROWS($1:2)-MATCH(FALSE,N(OFFSET(B2,-ROW(INDIRECT("1:"&ROWS($1:1))),,,))=B2,0)))

    This will give you results for both 0s and 1s.

    Regards

  7. #7
    Registered User
    Join Date
    08-21-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Calculating difference between two times through a column of data

    Hi XOR LX,

    I would like to have your babies.

    Thanks a million that worked a charm.

    Cheers,
    Going_loco

  8. #8
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Calculating difference between two times through a column of data

    Hahaha!!

    You're welcome!

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

    Re: Calculating difference between two times through a column of data

    The attached file shows how you can produce a summary table of the durations for zero and one. I've used column D as a helper column (coloured blue) with this formula in D1:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    and this formula in D2:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    which is then copied down to the bottom of your data. The idea is that transitions from 0 to 1 are shown with an increasing number which ends with 0.5, and transitions from 1 to 0 are shown with an increasing integer.

    Then I've put some headings in G1:H2 and the number 1 in F3 with this formula in F4:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    This formula is in G3:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    so that if your first value in B2 is a 1 this cell shows blank. A slightly different formula is used in G4:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Both cells are formatted as hh:mm:ss, and return the time differences for the zero values by looking for the time values between 0 and 0.5 (row 3) and between 1 and 1.5 (row 4). A similar formula is used for the 1's in H3:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    which is copied into H4, with both cells formatted as hh:mm:ss. You need to copy the formulae in F4:H4 down, and to assist you I've put another little formula in I4 to tell you how far, depending on your data.

    Hope this helps.

    Pete
    Attached Files Attached Files

+ 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. need help asap...calculating difference between 2 times
    By flipmagoo in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-05-2012, 10:09 AM
  2. Calculating difference in times as hours and minutes
    By Andrea112233 in forum Excel General
    Replies: 3
    Last Post: 08-10-2009, 10:23 AM
  3. Replies: 2
    Last Post: 07-06-2009, 12:30 PM
  4. Calculating the difference in 2 times
    By km1 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-24-2006, 04:42 PM
  5. Calculating difference between two times
    By Jaycatt in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-08-2006, 03:05 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