+ Reply to Thread
Results 1 to 23 of 23

Dynamic Averaging of column.

  1. #1
    Registered User
    Join Date
    10-18-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    67

    Question Dynamic Averaging of column.

    I have a column with random values that are generated my my machinery.
    I should not sort them, because they provide me with the performance graph.
    Lets say i have column "A"
    0
    2
    3
    9
    7
    90
    22
    5
    9
    0

    As the max value of this is 90, and its 10% of MAX is 9, which occurs at 4th and 9 th positions.
    I need to find the average of this range, with zeros not considered.
    It has to calculate the max value in the column, find 10% of max and do average from the first occurrence of 10% value to the last occurrence of 10% value.

    I need this urgently for my project work!

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

    Re: Dynamic Averaging of column.

    Hi,

    Assuming your data is in A2:A1000:

    =AVERAGE(INDEX(A2:A1000,MATCH(MAX(A2:A1000)*0.1,A2:A1000,0)):INDEX(A2:A1000,MATCH(2,INDEX(1/((A2:A1000=MAX(A2:A1000)*0.1)*ROW(A2:A1000)),,))))

    Regards
    Click * below if this answer helped

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

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

    Re: Dynamic Averaging of column.

    Edit: I just re-read your post and realise that you want zeroes within the range excluded from the average. Amend to:

    =AVERAGEIF(INDEX(A2:A1000,MATCH(MAX(A2:A1000)*0.1,A2:A1000,0)):INDEX(A2:A1000,MATCH(2,INDEX(1/((A2:A1000=MAX(A2:A1000)*0.1)*ROW(A2:A1000)),,))),"<>0")

    Regards

  4. #4
    Registered User
    Join Date
    10-18-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Dynamic Averaging of column.

    hope this works! Btw thanx for the help! Will check and post back!
    Quote Originally Posted by XOR LX View Post
    Edit: I just re-read your post and realise that you want zeroes within the range excluded from the average. Amend to:

    =AVERAGEIF(INDEX(A2:A1000,MATCH(MAX(A2:A1000)*0.1,A2:A1000,0)):INDEX(A2:A1000,MATCH(2,INDEX(1/((A2:A1000=MAX(A2:A1000)*0.1)*ROW(A2:A1000)),,))),"<>0")

    Regards

  5. #5
    Registered User
    Join Date
    10-18-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Dynamic Averaging of column.

    it is actually returning a #NA error!
    Quote Originally Posted by XOR LX View Post
    Edit: I just re-read your post and realise that you want zeroes within the range excluded from the average. Amend to:

    =AVERAGEIF(INDEX(A2:A1000,MATCH(MAX(A2:A1000)*0.1,A2:A1000,0)):INDEX(A2:A1000,MATCH(2,INDEX(1/((A2:A1000=MAX(A2:A1000)*0.1)*ROW(A2:A1000)),,))),"<>0")

    Regards

  6. #6
    Registered User
    Join Date
    10-18-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Dynamic Averaging of column.

    i think, that is because the exact 10% value doesn't exist or may not always exist. 10% of 90 is 9, but if the max value is 94, the 10% would be 9.4 which doesn't exist. then it has to take the nearest available predecessor in that case.

    Quote Originally Posted by XOR LX View Post
    Edit: I just re-read your post and realise that you want zeroes within the range excluded from the average. Amend to:

    =AVERAGEIF(INDEX(A2:A1000,MATCH(MAX(A2:A1000)*0.1,A2:A1000,0)):INDEX(A2:A1000,MATCH(2,INDEX(1/((A2:A1000=MAX(A2:A1000)*0.1)*ROW(A2:A1000)),,))),"<>0")

    Regards

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

    Re: Dynamic Averaging of column.

    I'll need to see a sheet then. Works fine for me.

    Regards

  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: Dynamic Averaging of column.

    "i think, that is because the exact 10% value doesn't exist or may not always exist. 10% of 90 is 9, but if the max value is 94, the 10% would be 9.4 which doesn't exist. then it has to take the nearest available predecessor in that case."

    Ah. Yes, this is something you definitely should've mentioned! Bear with me...

    Regards

  9. #9
    Registered User
    Join Date
    10-18-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Dynamic Averaging of column.

    i get values in decimals mostly and only some of them are perfect integers, thus this consideration goes with it,and also, my range is B14:B10013

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

    Re: Dynamic Averaging of column.

    Can you just clarify what you mean by "nearest available predecessor?

    So, if 9.4 didn't exist, but 9.5 and 8.6 did (and were the two absolutely closest in value), which would it be? Or did you have something else in mind by "predecessor"?

    Regards

  11. #11
    Registered User
    Join Date
    10-18-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Dynamic Averaging of column.

    "Can you just clarify what you mean by "nearest available predecessor?

    So, if 9.4 didn't exist, but 9.5 and 8.6 did (and were the two absolutely closest in value), which would it be? Or did you have something else in mind by "predecessor"?

    Regards"

    hmm... oh! this is much more tricky than I expected....
    Ohk, then it has to take 8.6, coz in my case, the values are generally not so far apart.
    if there is no 9.4, there is a high chance of 9.3 or 9.2 or at least 9.1 to exist.
    and even in the extreme case, when the 10% of max occurs the last, it has to take predecessor i.e. 8.6 preferred over 9.5

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

    Re: Dynamic Averaging of column.

    Hang on - are you sure you've thought this through?

    I mean, what if you have a situation such as:

    Max Value: 90

    No entries of 9 in the data, but one entry of 8.97 and two of 8.98

    8.97 is in row 1 (out of 13000)
    8.98 is in rows 12500 and 12950

    In this case, since you want to take the first occurrence of the nearest value less than or equal to 10% of the max, which is 8.98 in this case, you would end up taking the average over rows 12500:12950 only, though this seems a touch arbitrary since it is only 1/100th out of being rows 1:12950 (had 8.97 been the closest).

    Do you see what I mean? What exactly are you trying to do here? What statistic are you trying to represent?

    Regards

  13. #13
    Registered User
    Join Date
    10-18-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Dynamic Averaging of column.

    the values would actually be gradually increasing and then again decreasing, so i think such a problem will not occur. i would most probably have the 10% value within the first 30 "non zero" entries and reoccurring within the last 30 "non zero" entries.

    Quote Originally Posted by XOR LX View Post
    Hang on - are you sure you've thought this through?

    I mean, what if you have a situation such as:

    Max Value: 90

    No entries of 9 in the data, but one entry of 8.97 and two of 8.98

    8.97 is in row 1 (out of 13000)
    8.98 is in rows 12500 and 12950

    In this case, since you want to take the first occurrence of the nearest value less than or equal to 10% of the max, which is 8.98 in this case, you would end up taking the average over rows 12500:12950 only, though this seems a touch arbitrary since it is only 1/100th out of being rows 1:12950 (had 8.97 been the closest).

    Do you see what I mean? What exactly are you trying to do here? What statistic are you trying to represent?

    Regards

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

    Re: Dynamic Averaging of column.

    But if your data is ordered (rising to a peak then falling again, as you say, perhaps like a normal distribution) and you're wanting to take a statistical average of that data, you would be just as well-served using e.g. TRIMMEAN with a suitable percent for the second parameter.

    Regards

  15. #15
    Registered User
    Join Date
    10-18-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Dynamic Averaging of column.

    but trimmean uses the exact same amount of trimming every time.
    But in my case, the percentage of trimming changes with the change in max value.
    And also it is not possible that the first and last occurrences of 10% value is equidistant from both ends.

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

    Re: Dynamic Averaging of column.

    Can I assume that, to determine the latest occurrence of 10% of the mean (or nearest thereof), I can begin the search in a range from the max value onwards (since you said it is generally rising to this max, then falling again)?

    Basically, this is equivalent to saying that the first and last occurrences of these two end-points cannot both occur in the first half of the range (leading up to the max).

    Regards

  17. #17
    Registered User
    Join Date
    10-18-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    67

    Lightbulb Re: Dynamic Averaging of column.

    YES! That is how they occur. One occurrence before max and the other after max value.

    Quote Originally Posted by XOR LX View Post
    Can I assume that, to determine the latest occurrence of 10% of the mean (or nearest thereof), I can begin the search in a range from the max value onwards (since you said it is generally rising to this max, then falling again)?

    Basically, this is equivalent to saying that the first and last occurrences of these two end-points cannot both occur in the first half of the range (leading up to the max).

    Regards

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

    Re: Dynamic Averaging of column.

    Could you kindly upload a sample sheet with your desired results? It's getting a little difficult to do this purely theoretically, and it would be useful to have some data and an end result to aim for.

    Regards

  19. #19
    Registered User
    Join Date
    10-18-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Dynamic Averaging of column.

    Attached herein is a file. as the max value of changes, the position of the 10% value also changes.
    the formula has to consider that position change.

    Sample.xlsx

    Quote Originally Posted by XOR LX View Post
    Could you kindly upload a sample sheet with your desired results? It's getting a little difficult to do this purely theoretically, and it would be useful to have some data and an end result to aim for.

    Regards

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

    Re: Dynamic Averaging of column.

    Based on this sheet, try this array (important) formula:

    =AVERAGEIF(INDEX($B$2:$B$4759,MATCH(TRUE,ABS($B$2:INDEX($B$2:$B$4759,MATCH(MAX($B$2:$B$4759),$B$2:$B$4759,0))-MAX($B$2:$B$4759)*0.1)=MIN(ABS($B$2:INDEX($B$2:$B$4759,MATCH(MAX($B$2:$B$4759),$B$2:$B$4759,0))-MAX($B$2:$B$4759)*0.1)),0)):INDEX(INDEX($B$2:$B$4759,MATCH(MAX($B$2:$B$4759),$B$2:$B$4759,0)):$B$4759,MATCH(TRUE,ABS(INDEX($B$2:$B$4759,MATCH(MAX($B$2:$B$4759),$B$2:$B$4759,0)):$B$4759-MAX($B$2:$B$4759)*0.1)=MIN(ABS(INDEX($B$2:$B$4759,MATCH(MAX($B$2:$B$4759),$B$2:$B$4759,0)):$B$4759-MAX($B$2:$B$4759)*0.1)),0)),"<>0")

    Regards

  21. #21
    Valued Forum Contributor
    Join Date
    05-07-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    354

    Re: Dynamic Averaging of column.

    slightly tested VBA solution

    Please Login or Register  to view this content.
    Last edited by vandan_tanna; 10-23-2013 at 02:12 PM. Reason: Changed Application.usedrange to r.parent.usedrange
    Regards,
    Vandan

  22. #22
    Valued Forum Contributor
    Join Date
    01-10-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    651

    Re: Dynamic Averaging of column.

    looks like this is already solved, but i wanted to see if i could do it any simpler (doesn't look like it). Anyway, I believe this does exactly what you asked:

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


    but this much simpler formula also seems to work with your data-set:

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


    this simpler formula breaks if your data gaps up a little on one side or the other... ie say 10% of the max were 9, on one side you had a 8 and a 10 and on the other side you had a 7 and a 13. this second formula would not include the 7 in the average even though that is the closest value on that side of the max... not sure how precise you needed to be.

    both are array formulas btw.

  23. #23
    Registered User
    Join Date
    10-18-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Dynamic Averaging of column.

    Thanx a lot! this seems to be working very much fine!

    Quote Originally Posted by XOR LX View Post
    Based on this sheet, try this array (important) formula:

    =AVERAGEIF(INDEX($B$2:$B$4759,MATCH(TRUE,ABS($B$2:INDEX($B$2:$B$4759,MATCH(MAX($B$2:$B$4759),$B$2:$B$4759,0))-MAX($B$2:$B$4759)*0.1)=MIN(ABS($B$2:INDEX($B$2:$B$4759,MATCH(MAX($B$2:$B$4759),$B$2:$B$4759,0))-MAX($B$2:$B$4759)*0.1)),0)):INDEX(INDEX($B$2:$B$4759,MATCH(MAX($B$2:$B$4759),$B$2:$B$4759,0)):$B$4759,MATCH(TRUE,ABS(INDEX($B$2:$B$4759,MATCH(MAX($B$2:$B$4759),$B$2:$B$4759,0)):$B$4759-MAX($B$2:$B$4759)*0.1)=MIN(ABS(INDEX($B$2:$B$4759,MATCH(MAX($B$2:$B$4759),$B$2:$B$4759,0)):$B$4759-MAX($B$2:$B$4759)*0.1)),0)),"<>0")

    Regards

+ 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. Dynamic Averaging Code
    By carbonboywonder in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-23-2010, 08:13 AM
  2. Averaging Dynamic Number of Rows
    By Eric Miller in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-04-2010, 03:17 PM
  3. Replies: 1
    Last Post: 09-30-2007, 08:18 AM
  4. Averaging dynamic cell data over a one hour period?
    By forextrader in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-10-2006, 02:45 AM
  5. averaging N rows in column B which have a certain number in column A
    By g s in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-14-2005, 04:26 PM

Tags for this Thread

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