+ Reply to Thread
Results 1 to 24 of 24

Count number of rows where any date between start and finish are between 2 dates

  1. #1
    Registered User
    Join Date
    07-11-2014
    Location
    Australia
    MS-Off Ver
    MS365 (2208)
    Posts
    48

    Count number of rows where any date between start and finish are between 2 dates

    Hi,
    I've a set of start dates in Column A and a set of finish dates in Column B.
    In row 1 I've a set of dates i.e. D1 has 15 May and E2 hs 22 May.

    I need to count the rows/instances where any date between the date in column A and the date in Column B is between the date in example D1 and E1 or E1 and F1.
    Attached Files Attached Files

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,960

    Re: Count number of rows where any date between start and finish are between 2 dates

    In the complete absence of any expected results, a guess. In D2 copied across:

    =SUMPRODUCT(($A$3:$A$39<=D1)*($B$3:$B$39>=D1))
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,435

    Re: Count number of rows where any date between start and finish are between 2 dates

    Another interpretation:

    Please try in D3 and copy right and down:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    07-11-2014
    Location
    Australia
    MS-Off Ver
    MS365 (2208)
    Posts
    48

    Re: Count number of rows where any date between start and finish are between 2 dates

    ignore this comment.

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,960

    Re: Count number of rows where any date between start and finish are between 2 dates

    What comment?

    Have you tried either of the suggestions offered?

  6. #6
    Registered User
    Join Date
    07-11-2014
    Location
    Australia
    MS-Off Ver
    MS365 (2208)
    Posts
    48

    Re: Count number of rows where any date between start and finish are between 2 dates

    I'd like the formula to look collectively at column A and column B and return how many exist 'open' within the week of D1 and E1 example.

  7. #7
    Registered User
    Join Date
    07-11-2014
    Location
    Australia
    MS-Off Ver
    MS365 (2208)
    Posts
    48

    Re: Count number of rows where any date between start and finish are between 2 dates

    yes, yours doesn't work and the other doesn't give me the totals although perhaps the totals (Not checked yet) will work when work off Hans sheet.

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,960

    Re: Count number of rows where any date between start and finish are between 2 dates

    Could you please provide expected results (manually calculated) for D2 to D6?

  9. #9
    Registered User
    Join Date
    07-11-2014
    Location
    Australia
    MS-Off Ver
    MS365 (2208)
    Posts
    48

    Re: Count number of rows where any date between start and finish are between 2 dates

    I apologies if I'm being vague
    Attached Files Attached Files

  10. #10
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,435

    Re: Count number of rows where any date between start and finish are between 2 dates

    Please try in D2 of workbook in post #3 and copy to right
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by HansDouwe; 07-14-2023 at 03:48 AM.

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,960

    Re: Count number of rows where any date between start and finish are between 2 dates

    You know exactly what it all means - we don't, so closer explanations are needed.

    For my benefit, could you please explain the calculation you did mentally to arrive at 3 for the first count?

  12. #12
    Registered User
    Join Date
    07-11-2014
    Location
    Australia
    MS-Off Ver
    MS365 (2208)
    Posts
    48

    Re: Count number of rows where any date between start and finish are between 2 dates

    Hello,
    thanks, I think that works.
    Is there not a way to avoid the count if based on the many values you've returned? i.e. isn't there a way to avoid the many values you've returned?

  13. #13
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,960

    Re: Count number of rows where any date between start and finish are between 2 dates

    I now understand the numbers you gave. I'll leave this to Hans, as I have no idea how to do it without the large matrix below.

  14. #14
    Registered User
    Join Date
    07-11-2014
    Location
    Australia
    MS-Off Ver
    MS365 (2208)
    Posts
    48

    Re: Count number of rows where any date between start and finish are between 2 dates

    Thanks AliGW. I was in the process of explaining and then it refreshed and I lost it but you've got it!
    Hans?

  15. #15
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,960

    Re: Count number of rows where any date between start and finish are between 2 dates

    Give him time. This is going to be complex, if indeed possible. Patience is the key! I shall watch with interest.

  16. #16
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,435

    Re: Count number of rows where any date between start and finish are between 2 dates

    Please try in D2 and copy to right:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by HansDouwe; 07-14-2023 at 04:18 AM.

  17. #17
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,435

    Re: Count number of rows where any date between start and finish are between 2 dates

    I have been asked to provide some explanation about this formula.

    If period 1 does not coincide with period 2, then both the start date and end date of period 1 are less than the start date of period 2 or the start date and end date of period 1 are greater than the end date of period 2.
    In all other cases, the two periods are (partly) consided.

    To determine this easily, the function MEDIAN is used.
    The MEDIAN function finds the middle number from a series of numbers.
    If there are an even number of numbers, the average of the middle two numbers.
    So the median of 4 numbers is the average of the two middle numbers.

    The formula calculates the median of the two starting days and the two ending days of the two periods.
    If 2 periods do not coincide, the median will always lie between the end date of the earliest period and the start date of the latest period, so the median will not lie in either period.
    On the other hand, if 2 periods do partially coincide, then the median of these four days cannot fall outside the two periods.
    That is why it is tested whether the median falls within one of these periods.
    And if so, that counts as 1.

    With function MAP-LAMBDA this is then done for all periods in the column and
    with function SUM all 1's are counted.

    I found it difficult to explain this formula, but I hope the explanation helps.

    If you have any further questions, don't hesitate to ask them here.
    Last edited by HansDouwe; 07-14-2023 at 06:43 AM.

  18. #18
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,960

    Re: Count number of rows where any date between start and finish are between 2 dates

    That's really helpful - thank you!

  19. #19
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,914

    Re: Count number of rows where any date between start and finish are between 2 dates

    Or try this in D2:

    Please Login or Register  to view this content.

  20. #20
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,214

    Re: Count number of rows where any date between start and finish are between 2 dates

    Or

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  21. #21
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,960

    Re: Count number of rows where any date between start and finish are between 2 dates

    LOL!

    Looks like some of us were over-complicating this big time!!!

  22. #22
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,214

    Re: Count number of rows where any date between start and finish are between 2 dates

    @AliGW:

    You had it (almost!) correct in your post (#2)

    =SUMPRODUCT(($A$3:$A$39<=D1)*($B$3:$B$39>=D1))

    vs

    =SUMPRODUCT(($A$3:$A$39<=E1)*($B$3:$B$39>=D1))


  23. #23
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,435

    Re: Count number of rows where any date between start and finish are between 2 dates

    LOL, yes a little bit overcomplicating , but nevertheless it was fun to work on the formula.

  24. #24
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,960

    Re: Count number of rows where any date between start and finish are between 2 dates

    And it was useful learning, too.

    @AliGW:

    You had it (almost!) correct in your post (#2)
    Doh!!!

+ 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] Conditional Formatting of date ranges from start/ finish dates
    By shredder91 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-09-2021, 12:51 PM
  2. Project Start Date and Tasks Start/Finish Time
    By sammyb304 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-11-2019, 09:36 AM
  3. Replies: 2
    Last Post: 09-06-2018, 10:54 PM
  4. Replies: 7
    Last Post: 08-07-2018, 01:48 AM
  5. [SOLVED] Count Week numbers given start and finish week number
    By Vassen in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 09-30-2016, 01:59 AM
  6. Replies: 5
    Last Post: 06-30-2011, 03:26 PM
  7. [SOLVED] How do I chart date ranges with varying start and finish dates?
    By projectplanner in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 05-01-2005, 07:06 PM

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