+ Reply to Thread
Results 1 to 6 of 6

Avoid overlapping dates ranges (grouping)

  1. #1
    Registered User
    Join Date
    09-22-2018
    Location
    cordoba
    MS-Off Ver
    2010
    Posts
    2

    Avoid overlapping dates ranges (grouping)

    Hi, I'm stuck with this issue, please help!

    I have a variable set of dates ranges, and I need to assign each range a number (or label or category) and avoid overlapped ranges in the same label.
    So the numbers (or labels) will be the "Y-Series" for a timeline bar chart.

    I need to get the minimum number of "labels" with no overlapped ragnges (3 in the case below) and put that numer to each date range.
    So the fisrt range is ǵroup N1', if the start date of the second rage is bigger than the end date of the first, then it is assigned to group N1 too, otherwise, is the first range of group N° 2, and so on...

    Explample of the set:

    start date end date

    04/2008 06/2008
    04/2008 05/2008
    07/2008 08/2018
    07/2008 08/2008
    09/2008 07/2014
    08/2009 08/2009
    08/2011 08/2011
    12/2013 12/2013
    02/2014 07/2014
    09/2014 10/2014


    I need a formula to put a numer as shown at yhe left of the start date:


    1 04/2008 06/2008
    2 04/2008 05/2008
    1 07/2008 08/2018
    2 07/2008 08/2008
    2 09/2008 07/2014
    3 08/2009 08/2009
    3 08/2011 08/2011
    3 12/2013 12/2013
    3 02/2014 07/2014
    2 09/2014 10/2014


    Thanks!

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: Avoid overlapping dates ranges (grouping)

    Hi and welcome to the forum,

    I do not think it will be aesy to obtain with formulas only (and especially with easy formulas).
    I'd use such a simple (I focused on easy understanding, so it's not optimized for speed) VBA code:

    Please Login or Register  to view this content.
    Two notes
    - I followed presented layout of data - for instance no header row
    - dates in columns B and C has to be recognized by Excel as dates. Change formatting of one of these cells to General, and if you see a number like 40000+ in a cell, then it is a date. If it's still 04/2008 then you probably has text in a cell (which only looks like a date).

    See attached
    Attached Files Attached Files
    Best Regards,

    Kaper

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

    Re: Avoid overlapping dates ranges (grouping)

    I'm with Kaper

    I do not think it will be aesy to obtain with formulas only (and especially with easy formulas).
    that said, it seemed an interesting challenge -- these types of calcs are not my forte, I'm sure there's a MMULT type approach out there that would work, or some better logic.

    If we assumed your start dates are in B3:B12, and your end dates in C3:C12, enter 1 into A3 {first entry} and the below can then be applied to A4, and copied down - mirroring your expected results.

    Please Login or Register  to view this content.
    edit: updated 3pm UK, superfluous TRANSPOSEs removed, and removed Array entry requirement
    Last edited by XLent; 09-24-2018 at 10:05 AM.

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: Avoid overlapping dates ranges (grouping)

    Nice one!
    But if I can comment:
    Even after transposes removed and no array committment required - still wouldn't call it an easy formula

    Anyway: Rep+ from me
    Last edited by Kaper; 09-24-2018 at 11:23 AM. Reason: Added reputation

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

    Re: Avoid overlapping dates ranges (grouping)

    Thanks; yes, it's Volatile too (given use of INDIRECT) -- so I wouldn't be arguing it should be used...

    I just found the challenge interesting... and spent way too long that is acceptable trying to work out a suitable approach... in the end it's relatively straightforward logic:

    - create an array of values for all preceding rows such that the end date serial is appended as a decimal remainder of the associated label value
    - from the above array extract the "max" value for each label
    - above achieved via an outer SMALL in conjunction with a dynamic k array, the k array being determined by a COUNTIF relative to any / all labels used to that point
    - the date serial values can be removed from the SMALL results c/o MOD leaving just the date "decimal", in turn reverted to a date serial (c/o * and round)
    - the final test is then to see which is the first label with a current end date preceding the criteria (c/o MATCH) and use that as the result
    - if there is no such result a new label must be required (determined as max of preceding labels + 1)

    Note:
    I realise now, having typed out the above, that my final test is incorrect as it is testing the end date rather than the start date of the current row, and thus should in fact read:

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


    change being first cell reference now reads $B4 as opposed to $C4, remainder unchanged...

    just so happens that with the sample data you get the same results, either way ;-)
    Last edited by XLent; 09-24-2018 at 12:00 PM.

  6. #6
    Registered User
    Join Date
    09-22-2018
    Location
    cordoba
    MS-Off Ver
    2010
    Posts
    2

    Re: Avoid overlapping dates ranges (grouping)

    WOOOWWW, It works!!!

    I'm gonna have to burn my brain to understand why it works, but it does!!

    Thanks a lot to both!!

+ 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. Count Overlapping dates in multiple date ranges with a criteria
    By jenn.murphy in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-05-2016, 03:07 PM
  2. Overlapping Date ranges
    By pvd12 in forum Excel - New Users/Basics
    Replies: 9
    Last Post: 01-07-2016, 03:01 AM
  3. Create Unique Overlapping Date Ranges from List of Dates
    By dbs105 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-11-2015, 08:03 PM
  4. [SOLVED] Overlapping Dates, Gaps in Dates, Double Counting
    By arunkushvaha in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-19-2013, 11:15 PM
  5. Overlapping Dates, Gaps in Dates, Double Counting
    By sglxl in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-24-2012, 02:46 AM
  6. line dropping to avoid overlapping
    By tomi_robo in forum Excel General
    Replies: 0
    Last Post: 07-23-2012, 06:31 AM
  7. Overlapping ranges different rows
    By alexo in forum Excel General
    Replies: 1
    Last Post: 10-20-2010, 12:39 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