+ Reply to Thread
Results 1 to 11 of 11

Counting regular occurrences in a specified interval

  1. #1
    Registered User
    Join Date
    05-29-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Counting regular occurrences in a specified interval

    I'm having difficulty trying to tally the number of regular payments - both those that have already happened and those that are scheduled to happen - between two specified dates. Here is the general setup of inputs:

    B1: Interval Start Date
    B2: Interval End Date
    B3: First Payment Date
    B4: Next Scheduled Payment Date
    B5: Payment Frequency (monthly, quarterly, semi-annually, or annual)

    The payments occur at regular intervals according to one of the four possible frequencies, but the interval between the two dates can be any duration. Essentially this means I'm counting certain dates inside the interval. I don't have an entire column with each payment date, so I'm not sure how a COUNT function would work.

    I was able to solve this problem for the monthly frequency by using an array formula based on the day of the month as follows:

    B7 = # of monthly payments within interval =SUMPRODUCT(--(DAY(ROW(INDIRECT(B1&":"&B2)))=DAY(B3)))

    As an admitted Excel novice, I'm struggling to translate this same formula to cover the quarterly, semi-annual, and annual frequencies. I've tried using some clumsy AND/OR logic to account for which months and days should be counted, but I keep tripping over errors.

    If an example helps illustrate what I'm after, use these values:

    B1: 12/10/2011
    B2: 8/1/2012
    B3: 6/15/2010
    B4: 6/15/2012

    If B5 = Monthly, B7 = 8 (12/15, 1/15, 2/15, 3/15, 4/15, 5/15, 6/15, 7/15)
    If B5 = Quarterly, B7 = 3 (12/15, 3/15, 6/15)
    If B5 = Semi-Annual, B7 = 2 (12/15, 6/15)
    If B5 = Annual, B7 = 1 (6/15)

    Any help would be much appreciated.

    intervalcount.xls
    Last edited by dm2012; 05-30-2012 at 07:51 AM. Reason: attached example file

  2. #2
    Registered User
    Join Date
    05-29-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Counting regular occurrences in a specified interval

    Sorry, didn't include an attachment earlier. I added an example file so this made more sense.

  3. #3
    Registered User
    Join Date
    05-29-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Counting regular occurrences in a specified interval

    Bump no response

  4. #4
    Registered User
    Join Date
    05-29-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Counting regular occurrences in a specified interval

    bump, no response

  5. #5
    Registered User
    Join Date
    05-29-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Counting regular occurrences in a specified interval

    .................

  6. #6
    Registered User
    Join Date
    05-29-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Counting regular occurrences in a specified interval

    bump no response

  7. #7
    Forum Guru
    Join Date
    05-24-2011
    Location
    India
    MS-Off Ver
    Office 2021
    Posts
    2,237

    Re: Counting regular occurrences in a specified interval

    Hello dm,

    Try COUPNUM function. For Excel 2003 this might require Analysis ToolPak AddIn.

    =COUPNUM(B1,B2,4,1)

    Change 4 to,

    1 for Annual
    2 for Semiannual
    4 for Quarterly
    Regards,
    Haseeb Avarakkan

    __________________________________
    "Feedback is the breakfast of champions"

  8. #8
    Registered User
    Join Date
    05-29-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Counting regular occurrences in a specified interval

    This works perfectly. Thanks for your help Haseeb!

  9. #9
    Registered User
    Join Date
    05-29-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Counting regular occurrences in a specified interval

    Sorry Haseeb, I spoke too soon on this being solved. I tried "stress testing" this using different intervals and payment dates, and it appears what the COUPNUM formula is doing is just counting the number of starting points for periods of a given length between the two interval end points. Here's a couple of examples.

    Start Date: 7/10/2012
    End Date: 10/11/2012
    First Payment Date: 6/15/2010
    Next Payment Date: 9/15/2012
    Payment Frequency: 4 (quarterly)

    This information tells me that my payments are 3/15, 6/15, 9/15 and 12/15 every year. So I'm basically trying to count the occurrences of these dates between 7/10/2012 and 10/11/2012. The answer here should be 1 occurrence of a payment (9/15/2012), but the COUPNUM function returns 2 because it's saying "7/10 starts a quarter, and 10/10 starts another quarter".

    The same thing happens with other frequencies:

    Start Date: 7/10/2012
    End Date: 1/11/2013
    First Payment Date: 6/15/2010
    Next Payment Date: 12/15/2012
    Payment Frequency: 2 (semi-annual)

    Here, my payments are each 6/15 and 12/15, so 1 should occur during the specified interval (12/15/2012), but COUPNUM counts 2.

    I can't just tack a "subtract 1" onto the formula across the board either because sometimes the count happens to be right. What I really need is the ability to recognize what date(s) payments happen each year based on the First Payment Date, Next Payment Date, and Frequency, and then to pick out all occurrences of those dates in the specified interval.

  10. #10
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Counting regular occurrences in a specified interval

    Try this formula

    =MAX(0,(FLOOR(DATEDIF(B3,B2,"m"),12/B5)-FLOOR(DATEDIF(B3,B1-1,"m"),12/B5))/12*B5)

    Assumes B5 will be an integer factor of 12

    ...or an alternative...

    =MAX(0,SUMPRODUCT(FLOOR(DATEDIF(B3,B1:B2-{1;0},"m"),12/B5)/{-12;12})*B5)
    Audere est facere

  11. #11
    Registered User
    Join Date
    05-29-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Counting regular occurrences in a specified interval

    I think the first option has an extra parentheses at the end, but after removing that it looks like both versions work. I can't find an interval/frequency combo that doesn't match expected tally which is great. Marking this solved (for real this time).

    Sort of a followup and I don't know yet if I actually need to go this route, but if I wanted to only make one endpoint inclusive (e.g. if start date falls on a payment date don't count it, but if end date falls on a payment date do count it) how could I tweak? I assume I'd need a conditional "-1" somewhere. Probably could accomplish this with a clunky "IF" statement around your formulas, but you probably know of a cleaner way.

    Really appreciate your help daddylonglegs. Thanks!

+ 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