+ Reply to Thread
Results 1 to 9 of 9

Need help with calculating averages over dynamic ranges

  1. #1
    Registered User
    Join Date
    12-14-2020
    Location
    Amsterdam
    MS-Off Ver
    2016
    Posts
    4

    Need help with calculating averages over dynamic ranges

    Hello,

    I'm trying to get a formula right which helps me to return averages of specific vertical ranges from differing length in my Excel sheet.

    In column A, time stamps of the measurements are available, given as hh:mm:ss. In the second column, the measurements are listed. I want to calculate the avergae of the measurements (column B) from time windows 00:00:01 to 00:00:20, form 00:00:21 to 00:00:40, from 00:00:41 to 00:01:00 and so on. Within each time period of 20 seconds, the number of measurements differ. I've been tryign to get this right using offset and if, then formulas, but I can't get them to work.

    Example data are enclosed. Thanks!
    Attached Files Attached Files

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,446

    Re: Need help with calculating averages over dynamic ranges

    Hi
    with a small helper column you can create a Pivot Tabl like the attched

    Define your range as a Table to make the dynamic
    Attached Files Attached Files
    Last edited by Pepe Le Mokko; 12-14-2020 at 03:55 AM.

  3. #3
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,996

    Re: Need help with calculating averages over dynamic ranges

    Creating a time range can sometimes be problematic!! as you have seen.... It's all down to floating point aritmentic... rounding errors.

    With 00:00:01 in E2 and 00:00:20 in F2, use these to create the time series in E3:=E2+$F$2 and in F3: $F$2+F2

    Now a nice simple averageifs will work in G2:

    =IFERROR(AVERAGEIFS(B:B,A:A,">="&E2,A:A,"<="&F2),"")

    You may need ; instead of , - see the sheet for context.
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  4. #4
    Registered User
    Join Date
    12-14-2020
    Location
    Amsterdam
    MS-Off Ver
    2016
    Posts
    4

    Re: Need help with calculating averages over dynamic ranges

    Thanks to the both of you! This was very helpful.

    Glenn, your solution is near to perfect, although if you calculate averages by hand for the specified windows, the results are slightly different than the results from the formula you have provided.
    I've been trying to correct this, but the problem still exists; I think it might be due to measurements made at the cut-off values of time windows. Is there a way to work around this issue?

    Thanks again!

  5. #5
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,463

    Re: Need help with calculating averages over dynamic ranges

    With Glenn's, make a slight amenmend:
    G2: leave as it was.
    In G3:
    Please Login or Register  to view this content.
    Drag down
    Quang PT

  6. #6
    Registered User
    Join Date
    12-14-2020
    Location
    Amsterdam
    MS-Off Ver
    2016
    Posts
    4

    Re: Need help with calculating averages over dynamic ranges

    Thank you for your help, but this does not seem to solve the issue. See the updated test data enclosed. There is still a mismatch between averag and "correct" average...
    Attached Files Attached Files

  7. #7
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,996

    Re: Need help with calculating averages over dynamic ranges

    Time starts at zero, not at one second. So, I changed E2 to zero, as you are wanting average of 20 second blocks from t=0. That has no material effect in the "discrepancies" as there was none in the first block. It just makes it correct!!

    You are averaging 20 second blocks. >0-20. >20-40. >40-60, etc. The difference is in the milliseconds, which you could not see when data were presented as hh:mm:ss.

    See sheet.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    12-14-2020
    Location
    Amsterdam
    MS-Off Ver
    2016
    Posts
    4

    Re: Need help with calculating averages over dynamic ranges

    Hi Glenn,

    Thank again, also for the clear visual explanation with the time stamps showed with their decimals. This explains the "discrepancies", that were no discrepancies after all.

    Cheers!

  9. #9
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,996

    Re: Need help with calculating averages over dynamic ranges

    You're welcome.



    If that takes care of your original question, please select "Thread Tools" from the menu link above and mark this thread as SOLVED.

    It'd also be appreciated if you were to click the Add Reputation button at the foot of any of the posts of all members who helped you reach a solution.

+ 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. Calculating Averages
    By ozirambler in forum Excel General
    Replies: 1
    Last Post: 05-11-2020, 10:03 PM
  2. calculating averages
    By rjc_29 in forum Excel General
    Replies: 2
    Last Post: 08-24-2011, 03:18 PM
  3. Calculating Averages Using VBA
    By Sugar Ape in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-28-2009, 07:37 AM
  4. Calculating averages
    By mr_teacher in forum Excel General
    Replies: 5
    Last Post: 11-09-2007, 02:47 PM
  5. Calculating Averages
    By Slave2Six in forum Excel General
    Replies: 3
    Last Post: 08-24-2006, 02:17 PM
  6. Calculating dynamic moving averages
    By dmax007 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-07-2006, 04:30 PM
  7. Calculating Averages
    By Dani in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-07-2005, 12: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