+ Reply to Thread
Results 1 to 9 of 9

Calculating Moving Range with Blank Cells

  1. #1
    Registered User
    Join Date
    06-30-2010
    Location
    Tucson, Arizona
    MS-Off Ver
    Excel 2007
    Posts
    58

    Calculating Moving Range with Blank Cells

    Hello all,

    I am attempting to create a control chart for some data, and need an average moving range (MR bar). This would be simple if my data was all together in column A, simply using something like...

    Please Login or Register  to view this content.
    However, I have blank cells which for all intensive purposes I want to pretend aren't there. I was thinking maybe a conditional statement used in conjunction with a lookup argument may get me there, but I am having trouble.

    example data

    Data
    1.914535
    1.803167



    2.091054
    1.983503


    2.014628


    1.789016
    1.827065
    1.86465

    1.938139
    1.96658

    1.878581
    1.867826


    Using a manual method and the above code and data (copy and pasting into excel) I get:

    MR_Bar=0.09453282
    Last edited by montego; 07-15-2010 at 06:18 PM.

  2. #2
    Registered User
    Join Date
    06-30-2010
    Location
    Tucson, Arizona
    MS-Off Ver
    Excel 2007
    Posts
    58

    Example Sheet

    Posted.

    Thanks in advance!
    Attached Files Attached Files

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Calculating Moving Range with Blank Cells

    In terms of replicating your manual calcs. in column D with a consistent formula

    D4:
    =IF(AND(ISNUMBER($C4),COUNT($C$4:$C4)>1),ABS($C4-LOOKUP(9.99E+307,$C$3:$C3)),"")
    copied down

    A single cell calculation would be more convoluted - not clear if that's the requirement or not.

  4. #4
    Registered User
    Join Date
    06-30-2010
    Location
    Tucson, Arizona
    MS-Off Ver
    Excel 2007
    Posts
    58

    Re: Calculating Moving Range with Blank Cells

    Thanks DonkeyOte,

    Please Login or Register  to view this content.
    worked flawlessly copied down. I would love to not have to use a helper column, but I feel that if the calculation is this difficult with the helper cells, a single cell solution would be nearly impossible to code. However, it would be ideal

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Calculating Moving Range with Blank Cells

    TBH I have been unable to conjure anything up to do this in a single cell (ie without helpers).

    The complexity [for me] is establishing a method by which to create an appropriate array of values where each value is the prior numeric value for each numeric value found in the data set.
    (the difficulty arises given a) interspersed blanks b) data points are not in order [understandably])

    There is probably a way, however, if it exists it will be hideous, inefficient and Volatile (SUBTOTAL/OFFSET requirement)

    To certify that I did think about it... note it doesn't work as it's WIP:

    =AVERAGE(IF((SUBTOTAL(2,OFFSET($C$4,0,0,ROW($C$4:$C$24)-ROW($C$4)+1,1))>1)*SUBTOTAL(2,OFFSET($C$4,ROW($C$4:$C$24)-ROW($C$4),0)),ABS($C$4:$C$24-0)))
    CTRL + SHIFT + ENTER

    the remaining issue is of course replacing the 0 with an appropriate Array of values and this is the hard bit
    the array should contain n-1 numeric values (where n = data points), each value is the prior numeric value for a given data point

    because the data point values are not sorted (understandable) this precludes using a SUBTOTAL(4 approach against an increasingly large OFFSET range
    given the "n" values (B) appear irrespective of adjacent numerical data point you can't use that value either (could then have used a SUMIF to retrieve value)

    ... to top it all I can't get a LOOKUP approach to work either !

    edit: I don't like to concede defeat on a formula calculation so I will continue to think about if only for the challenge (or until such time as another kind soul resolves)
    Last edited by DonkeyOte; 07-16-2010 at 04:34 AM.

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Calculating Moving Range with Blank Cells

    Just to elaborate regards:

    Quote Originally Posted by D.O
    given the "n" values (B) appear irrespective of adjacent numerical data point you can't use that value either (could then have used a SUMIF to retrieve value)
    If we were to change B4:B24 such that:

    B4: =ROWS(B$4:B4)*SIGN($C4)
    copied down to B24

    Then in theory you could use:

    =AVERAGE(IF((SUBTOTAL(2,OFFSET($C$4,0,0,ROW($C$4:$C$24)-ROW($C$4)+1,1))>1)*SUBTOTAL(2,OFFSET($C$4,ROW($C$4:$C$24)-ROW($C$4),0)),ABS($C$4:$C$24-SUMIF($B$3:$B$23,SUBTOTAL(4,OFFSET($B$3,0,0,ROW($B$3:$B$23)-ROW($B$3)+1,1)),$C$3:$C$23))))
    confirmed with CTRL + SHIFT + ENTER

    But I accept that this is still in effect use a helper calculation along the way (such that the n values in Column B are adjusted based on whether or not there is an adjacent data point)

    And in reality that's not the best use of a helper cell as we've seen
    Last edited by DonkeyOte; 07-16-2010 at 04:48 AM.

  7. #7
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Calculating Moving Range with Blank Cells

    One way is to use this formula

    =AVERAGE(ABS(N(OFFSET(C4,SMALL(IF(ISNUMBER(C4:C24),ROW(C4:C24)-ROW(C4)),ROW(INDIRECT("2:"&COUNT(C4:C24)))),0))-N(OFFSET(C4,SMALL(IF(ISNUMBER(C4:C24),ROW(C4:C24)-ROW(C4)),ROW(INDIRECT("1:"&COUNT(C4:C24)-1))),0))))

    confirmed with CTRL+SHIFT+ENTER
    Audere est facere

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Calculating Moving Range with Blank Cells

    Thanks for looking at this dll - that's very clever indeed.

  9. #9
    Registered User
    Join Date
    06-30-2010
    Location
    Tucson, Arizona
    MS-Off Ver
    Excel 2007
    Posts
    58

    Re: Calculating Moving Range with Blank Cells

    Very clever indeed daddylonglegs. I have put both DonkeyOtes suggestion and daddylonglegs suggestions in the example sheet posted below.

    Thank you both for your solutions!
    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)

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