+ Reply to Thread
Results 1 to 13 of 13

Calculating Months/Yr including partial months

  1. #1
    Registered User
    Join Date
    01-27-2011
    Location
    Rochester, NY
    MS-Off Ver
    Excel 2007
    Posts
    19

    Question Calculating Months/Yr including partial months

    Hello - I am trying to calculate the number of months in between two dates for a given year. The formula needs to take into account partial months as the number of days divided by the number of days in that month so 30 if November, 29 if February on a leap year, etc. The attached spread sheet shows for example what I need. I've been working on this for a while and can't get it right.

    I started with lookups and countif and have a list of all days since January 2004 in a look-up range, but besides not giving me the exact answer there has to be a simpler way than listing all days in a lookup/reference table. Any help would be greatly appreciated!!
    Attached Files Attached Files
    Last edited by run2win17; 02-01-2011 at 02:52 PM.

  2. #2
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Calculating Months/Yr including partial months

    Hi
    What happens if the number of months is not an integer ? Roundup or rounddown



    EDIT to get the number of whole months between 2 dates, try
    Please Login or Register  to view this content.


    Is that what you need ?
    Last edited by arthurbr; 02-01-2011 at 12:07 PM.

  3. #3
    Registered User
    Join Date
    01-27-2011
    Location
    Rochester, NY
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Calculating Months/Yr including partial months

    No, the answer can't be an integer, it needs to show partial months as well. The attached *.xls shows an example as it's sort of hard to explain. Thanks for taking a stab at this!

  4. #4
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Calculating Months/Yr including partial months

    The following will give you the number of months and days.

    Please Login or Register  to view this content.
    If you want to calculate the days as fraction of months, you will have to define what happens if there are some days before the beginning of a whole month, and some days after the end

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Calculating Months/Yr including partial months

    Are you running exclusively on XL2007 and above or do you need backwards compatibility ?
    If the latter - are you able to utilise Analysis ToolPak ? (you can do with/without but "with" will allow for shorter formulae)

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Calculating Months/Yr including partial months

    I'm shooting off line for a bit but assuming answers to the above are either a) 2007+ or b) pre XL2007 but ATP ok; then:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-27-2011
    Location
    Rochester, NY
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Calculating Months/Yr including partial months

    That worked perfectly DonkeyOte, THANK YOU!!

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

    Re: Calculating Months/Yr including partial months

    Slightly different approach but should get the same results.....

    Assuming you put the year in row 4 as per DonkeyOte's suggestion, then you could use this formula in D7 copied across and down

    =SUMPRODUCT(FREQUENCY(ROW(INDIRECT($B7&":"&$C7-1)),DATE(D$4,{1;2;3;4;5;6;7;8;9;10;11;12;13},0))/DAY(DATE(D$4,{1;2;3;4;5;6;7;8;9;10;11;12;13;14},0)),{0;1;1;1;1;1;1;1;1;1;1;1;1;0})
    Audere est facere

  9. #9
    Registered User
    Join Date
    01-27-2011
    Location
    Rochester, NY
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Calculating Months/Yr including partial months

    Thanks daddylong legs, that worked as well!

  10. #10
    Registered User
    Join Date
    01-27-2011
    Location
    Rochester, NY
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Calculating Months/Yr including partial months

    daddylonglegs - would you be able to provide a modification to your code that assumes every month is 30 days long and calculates whole/partial months under that assumption?

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

    Re: Calculating Months/Yr including partial months

    I suppose it depends exactly how you would treat dates like 31st March......but you could try this version with YEARFRAC function.

    In D7 copied across and down

    =IF(($B7<DATE(D$4+1,1,1))*($C7>DATE(D$4,1,1)),YEARFRAC(MAX($B7,DATE(D$4,1,1)),MIN($C7,DATE(D$4+1,1,1))),0)*12

  12. #12
    Registered User
    Join Date
    01-27-2011
    Location
    Rochester, NY
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Calculating Months/Yr including partial months

    works perfectly - thanks!

  13. #13
    Registered User
    Join Date
    05-24-2017
    Location
    United States
    MS-Off Ver
    2007
    Posts
    1

    Re: Calculating Months/Yr including partial months

    I cannot open the Excel file attached to the thread to view what the formulas are pulling for but am in need of a similar formula.

    I need to figure out a formula for calculating partial months between two dates where the first month is always counted as a full month and the final month is only considered a full month if the date falls after the 15th.

    Ex: 1/30/2017 is the start date and 4/19/2017 is the end date.

    The current formula I am using =DATEDIF(0,H37,"ym")&" months "&DATEDIF(0,H37,"md")&" days" gives a result of two months and 19 days but I need a formula to recognize this as four months.

    Any help is much appreciated.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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