+ Reply to Thread
Results 1 to 3 of 3

Deciphering a Complicated Formula to Calculate Peak to Trough Change

  1. #1
    Forum Contributor
    Join Date
    02-08-2005
    MS-Off Ver
    Microsoft 365
    Posts
    810

    Deciphering a Complicated Formula to Calculate Peak to Trough Change

    Hi,

    I have the following formula that calculates the Maximum Drawdown from a series of values in A3:A63:

    {=MIN(IFERROR($A$3:$A$63/SUBTOTAL(4,OFFSET($A$3:$A$63,-1,,ROW(INDIRECT("1:"&ROWS($A$3:$A$63))),))-1,""))}

    The Maximum Drawdown is the largest drop from peak to trough in a series of values.

    Can someone please explain how the above formula works to calculate this?

    Thanks!
    Last edited by andrewc; 06-22-2019 at 04:30 AM.

  2. #2
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: Deciphering a Complicated Formula to Calculate Peak to Trough Change

    always best to break down into component parts, and where possible to work in from out when evaluating

    {=MIN(IFERROR($A$3:$A$63/SUBTOTAL(4,OFFSET($A$3:$A$63,-1,,ROW(INDIRECT("1:"&ROWS($A$3:$A$63))),))-1,""))}

    - the ROWS call will return 60, so coupled with the "1:"& this will creates a string --> "1:60"
    - the above string is then applied to the outer INDIRECT to, effectively, cast the String to a Range
    - the outer ROW call is made against the range

    so, at this point, you have a 60 element Array from 1 through 60 - i.e. {1;2;3;4;5;....;60}

    this array is used within the OFFSET to generate 60 different ranges relative to the outer range A3:A63

    OFFSET(reference,rows,cols,[height],[width])

    the [ ] denote non-mandatory

    so your OFFSET range reference is A3:A63
    - this is initially offset / moved up a row (-1) to become A2:A62
    - no change is applied to the columns (i.e. just , ... I don't like this and would use 0 as easier to read-back)
    - the optional height variable is where your 1-60 array comes in as it generates 60 ranges of increasing height (from 1 cell to 60 high)
    - the optional column variable is left untouched (again done via , I would use explicit value 1 as easier to read-back - i.e. 1 column wide)

    so, at this point you now have 60 ranges, A2:A2, A2:A3, A2:A4 etc... through A2:A62

    the SUBTOTAL is then applied to each of these 60 ranges, used with option 4 this will return the MAX value from each.

    so, at this point, you have 60 values with each value representing the MAX value from each of the 60 ranges

    the calc is then dividing each of the 60 MAX values by the respective value in A3:A63, i.e.

    - A3 is divided by MAX value from Range 1 (item 1 in the SUBTOTAL array)
    - A4 is divisied by MAX value from Range 2 (item 2 in the SUBTOTAL array)
    ...
    - A63 divided by MAX value from Range 60 (item 60 in the SUBTOTAL array)

    the outer IFERROR is there to discount any errors that arise c/o division (i.e. if MAX were 0 or error), and replaces these values in the Array with a Null String

    so, you know have 60 values in the final array against which you will apply the MIN, these values are either Null strings, or legitimate results of the earlier division

    HTH

  3. #3
    Forum Contributor
    Join Date
    02-08-2005
    MS-Off Ver
    Microsoft 365
    Posts
    810

    Re: Deciphering a Complicated Formula to Calculate Peak to Trough Change

    That's a great answer, thank you very much!!!

+ 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. [SOLVED] Highest peak to Lowest trough
    By jonkaal in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 04-01-2016, 03:28 AM
  2. Replies: 6
    Last Post: 05-01-2015, 12:02 PM
  3. find peak and trough in data
    By qwertyjjj in forum Excel General
    Replies: 3
    Last Post: 04-23-2015, 04:01 PM
  4. Replies: 1
    Last Post: 12-17-2014, 11:28 PM
  5. peak to trough timeline
    By aldica in forum Excel General
    Replies: 1
    Last Post: 12-12-2014, 06:46 PM
  6. Finding Peak and Trough
    By VJR in forum Excel Charting & Pivots
    Replies: 6
    Last Post: 05-01-2014, 11:01 AM
  7. How to Calculate Peak and Off Peak Hours
    By nikolasp in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-01-2005, 12:00 AM

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