+ Reply to Thread
Results 1 to 5 of 5

Conditional MAX Statement?

  1. #1
    Registered User
    Join Date
    11-07-2011
    Location
    Scotland
    MS-Off Ver
    Excel 2003
    Posts
    5

    Conditional MAX Statement?

    I'm trying to find a maximum (positive) difference between a range of values, with certain constraints.

    Column A contains the values; Column B contains the date on which those values were recorded:

    Column A Column B

    22 May 10 2007
    19 May 17 2007
    44 May 24 2007
    17 May 21 2007

    The constraint is that for any solution, the lower value must have been recorded at an earlier date than the higher value. Therefore, while this appears to work:

    =(MAX(A1:A4)-(MIN(A1:A4)))

    it returns a value of '27' the difference between '44' and '17'. What I want is to put in a conditional which prohibits this and instead comes up with '44-19', as this would satisfy my requirement that the higher value '44' occurred on a later date than the lower '19'--even though the difference is only 25 and is thus not truly the 'maximum difference'.

    Is there any way to implement such a condition? I'm interested in a general solution--the fact that the conditional is assessed against a 'date' isn't all that critical per se. I just want to know if its possible to create a conditional MAX statement that uses a second column as the constraint in this way.

    Thanks for any ideas!
    Last edited by ExpatYankee; 11-18-2011 at 10:30 AM.

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Conditional MAX Statement?

    I would suggest:

    =MAX(A1:A4)-MIN(IF(B1:B4<INDEX(B1:B4,MATCH(MAX(A1:A4),A1:A4,0)),A1:A4))

    Confirmed with Ctrl+Shift+Enter as it's an array formula.

    What confuses me is in your example 17 is at an earlier date than 44 so that seems right.

    Dom
    Last edited by Domski; 11-18-2011 at 09:23 AM.
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Conditional MAX Statement?

    Perhaps?

    =MAX(A1:A4)-MIN(A1:INDEX(A1:A4,MATCH(MAX(A1:A4),A1:A4,0)))
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  4. #4
    Registered User
    Join Date
    11-07-2011
    Location
    Scotland
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Conditional MAX Statement?

    Domski, NBVC:

    Thank you both. This is exactly what I needed, and you've saved me a ton of time, effort and gnawed fingernails.

    Thanks again!

  5. #5
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Conditional MAX Statement?

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ 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