+ Reply to Thread
Results 1 to 10 of 10

Finding Min/Max for Dynamic Date Range

  1. #1
    Registered User
    Join Date
    08-23-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    10

    Finding Min/Max for Dynamic Date Range

    I have a series of dates (consecutive weeks) each of which falls into one of 4 period. The dates are dynamic based on a given start date. The period assignments are manual inputs that change from use case to use case.

    How do I identify the Start and End dates of each period? Please keep in mind the dates, number of periods, and duration of periods change from use case to use case.

    I thought about using a MIN and MAX to find the stand and end dates in a given range, but I'm having difficulty writing an INDEX(MATCH,MATCH) formula that will identify the range dynamically from which to select the MAX and MIN.

    The attached spreadsheet includes the dates and period assignments. Book1.xlsx

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,377

    Re: Finding Min/Max for Dynamic Date Range

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


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



    Both formulae are Array Functions and must be committed with Ctrl-Shift-Enter rather than just Enter


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Finding Min/Max for Dynamic Date Range

    Hi and welcome to the foum

    You didnt supply any actual data in your workbook, but assuming it would be in row 3, try this ARRAY function in C7, copied down...
    =MAX(IF($B$2:$Q$2=A7,$B$3:$Q$3,0))

    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer. Press F2 on that cell and try again.

    change the MAX to MIN (to get min)

    Edit: missed the part where you wanted the START and END dates (Trevor didnt though)
    =MAX(IF($B$2:$Q$2=A7,$B$1:$Q$1,0))
    Last edited by FDibbins; 10-19-2013 at 07:33 PM.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Finding Min/Max for Dynamic Date Range

    B7 =index($b$1:$aP$1,match(a7,$b$2:$aP$2,0))
    c7 =LOOKUP(A7,$B$2:$AP$2,$B$1:$AP$1)
    Last edited by martindwilson; 10-19-2013 at 07:36 PM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  5. #5
    Valued Forum Contributor
    Join Date
    09-07-2006
    Posts
    520

    Re: Finding Min/Max for Dynamic Date Range

    Put in B7, press CTRL+SHIFT+ENTER to confirm the array formula:
    =INDEX($B$1:$Q$1,MATCH(MIN(IF($B$2:$Q$2=$A7,COLUMN($B$2:$Q$2))),COLUMN($B$2:$Q$2),0))

    Put in C7, press CTRL+SHIFT+ENTER to confirm the array formula:
    =INDEX($B$1:$Q$1,MATCH(MAX(IF($B$2:$Q$2=$A7,COLUMN($B$2:$Q$2))),COLUMN($B$2:$Q$2),0))

    Select B7:C7, copy down to C10. Format as dates
    -------------------------------------------------
    Success? Celebrate it, click the little star at the bottom left of my responses

  6. #6
    Registered User
    Join Date
    08-23-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Finding Min/Max for Dynamic Date Range

    Thank you!!

    Trevor's solution worked like a charm!

  7. #7
    Registered User
    Join Date
    08-23-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Finding Min/Max for Dynamic Date Range

    Hi Martin--

    I plugged your solution in and it worked as promised. Can you help me understand how it works? I'm familiar with both INDEX(MATCH) and LOOKUP, but I'm left scratching my head as to why the INDEX(MATCH) returns the smallest date and the LOOKUP returns the largest.

    Any insights into how that works?

    Thanks!

  8. #8
    Registered User
    Join Date
    08-23-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Finding Min/Max for Dynamic Date Range

    Quote Originally Posted by martindwilson View Post
    B7 =index($b$1:$aP$1,match(a7,$b$2:$aP$2,0))
    c7 =LOOKUP(A7,$B$2:$AP$2,$B$1:$AP$1)
    Hi Martin--

    I plugged your solution in and it worked as promised. Can you help me understand how it works? I'm familiar with both INDEX(MATCH) and LOOKUP, but I'm left scratching my head as to why the INDEX(MATCH) returns the smallest date and the LOOKUP returns the largest.

    Any insights into how that works?

    Thanks!

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,377

    Re: Finding Min/Max for Dynamic Date Range

    You're welcome. Thanks for the rep.



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


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    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


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  10. #10
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Finding Min/Max for Dynamic Date Range

    B7 =index($b$1:$aP$1,match(a7,$b$2:$aP$2,0))
    c7 =LOOKUP(A7,$B$2:$AP$2,$B$1:$AP$1)
    match simply finds the first instance
    and because row 2 is in ascending order lookup finds the last value that = the lookup value so lookup 3 in the array 1,1,2,2,2,3,3,3,3,4
    it finds the position of the last 3 (position 9)and returns the corresponding value from the result vector

+ 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] dynamic date range
    By weeble33 in forum Excel General
    Replies: 5
    Last Post: 07-08-2013, 01:44 PM
  2. Finding a date in a text string and comparing it to a date range
    By ABARAN1000 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-05-2012, 02:55 PM
  3. [SOLVED] Dynamic named range based on a start date and end date
    By Gary Lockton in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 08-06-2012, 07:26 PM
  4. [SOLVED] Finding dynamic range
    By hardik.r.shah in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-03-2012, 01:30 AM
  5. [SOLVED] Finding dates within a date range
    By Marcus in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-04-2005, 09:06 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