+ Reply to Thread
Results 1 to 9 of 9

Summing DATEDIF Column

  1. #1
    Registered User
    Join Date
    12-17-2009
    Location
    London, England
    MS-Off Ver
    2016 and 365
    Posts
    17

    Summing DATEDIF Column

    Hi,

    I can't seem to find a solution for Summing a column with a DATEDIF forumla in. The number of rows can reach over a 100. For example:

    Column A and B are dates entred for this year.

    06-Jan 28-Jan 23 days
    07-Jan 05-Apr 89 days
    15-Jan 28-Jan 14 days
    17-Jan 05-Feb 20 days

    In Column C
    =IF((ISBLANK(A1)),"",IF(ISBLANK(B1),(DATEDIF(A1,TODAY()+1,"d")&" days "),(DATEDIF(A1, B1+1,"d"))&" days "))

    So I am looking to sum up column C.

    Any ideas?

    Thanks,

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Summing DATEDIF Column

    Depending on which version of Excel you're actually using (don't know if your profile is up to date or not) you could try either of the below:
    =SUM(SUBSTITUTE(C1:C4," days","")*1)
    =SUMPRODUCT(SUBSTITUTE(C1:C4," days","")*1)


    BSB

  3. #3
    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,253

    Re: Summing DATEDIF Column

    Simply remove the "days" text from the formula and then SUM.

  4. #4
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Summing DATEDIF Column

    =SUMPRODUCT((A1:A4>0)*(B1:B4>0)*(B1:B4-A1:A4+1))+SUMPRODUCT((A1:A4>0)*(B1:B4="")*(TODAY()-A1:A4+1)) although their may be a more succinct answer

    or
    =IF((ISBLANK(A1)),"",IF(ISBLANK(B1),today()+1 -a1,b1-A1+1))

    format cells as custom format 0 \d\a\y\s

    then you can sim these with a normal sum function

  5. #5
    Registered User
    Join Date
    12-17-2009
    Location
    London, England
    MS-Off Ver
    2016 and 365
    Posts
    17

    Re: Summing DATEDIF Column

    Thanks for the reply guys but I am having a bit of trouble still.

    1. The rows can go to infinity, and are always being input, is there a way to add to SUM the whole C column for when extra data is input, without having to change the formula every time?

    2. The first row is actually a title? so row A is text, does will this effect how to sum column C?

    johntropley - This solution didnt seem to work for me? Not sure why or if I did it wrong. It kept coming back with a value of 0.


    BSB =SUM(SUBSTITUTE(C1:C4," days","")*1) This one seemed to work the best, however I wasn't able to get it to work for the whole of the C coloumn, as in for soon as it goes past a cell without any data, if just errors. Currently I'm down to row 55 so (C2:C55), but soon as I hit (C2:C56) which is a blank cell, comes up with VALUE error. Is there a way so this works to infinity?

    Thanks again for your helps guys!

  6. #6
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Summing DATEDIF Column

    You could use a "dynamic named range" that will expand/contract as you add/remove data.

    Press Ctrl+F3 to open the Name Manager window and create a new named range called "DaysTotal".
    In the formula section of the window enter the below:
    =OFFSET(Sheet1!$C$1,0,0,COUNTA(Sheet1!$C:$C),1)

    Then change the formula to this:
    =SUM(SUBSTITUTE(DaysTotal," days","")*1)

    Change your original formula to:
    =IF((ISBLANK(A1)),0,IF(ISBLANK(B1),(DATEDIF(A1,TODAY()+1,"d")&" days "),(DATEDIF(A1, B1+1,"d"))&" days "))

    Change the custom formatting of column C to #"" (this will leave the cells with 0 looking blank/empty but stops the formula falling over)

    Now when you add remove data the formula will only be looking at the range data is entered into.

    See attached.

    All seems like a lot of effort when Mr Topley's reply give a nice simple solution.

    BSB
    Attached Files Attached Files
    Last edited by BadlySpelledBuoy; 07-02-2021 at 08:03 AM.

  7. #7
    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,253

    Re: Summing DATEDIF Column

    See attached

    =IF((ISBLANK(A2)),"",IF(ISBLANK(B2),(DATEDIF(A2,TODAY()+1,"d")),(DATEDIF(A2, B2+1,"d"))))
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    12-17-2009
    Location
    London, England
    MS-Off Ver
    2016 and 365
    Posts
    17

    Re: Summing DATEDIF Column

    Perfect!!!

    Thanks guys, managed to go for the simple answer from John Topley and get it to work.

    Not sure why I couldn't work it out for myself as it seems so simple. Maybe I had been staring at it for too long.

    and thanks BSB, I might try looking at creating a dynamic named range eventually, its something I havent done before, but think I might try out when I get a bit of spare time

  9. #9
    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,253

    Re: Summing DATEDIF Column

    See attached which adds formula to column C starting row 2
    Please Login or Register  to view this content.
    sum in F2
    Attached Files Attached Files
    Last edited by JohnTopley; 07-02-2021 at 09:42 AM.

+ 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] DATEDIF - DATEDIF Calculation returning a negative for days or months
    By DaveBre in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 08-27-2015, 06:22 PM
  2. Finding names in a column then summing figures to the right of that column
    By snoopy77 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 04-30-2015, 04:57 AM
  3. macro for filtering A column and summing up respective cells in B column
    By rajkumarmp in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-27-2013, 11:12 AM
  4. [SOLVED] Summing parts of a column based on the contents of another column
    By nimmer in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-09-2013, 11:33 AM
  5. Summing a column where matches adjacent column and colating results
    By rlamb in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-17-2013, 08:24 AM
  6. DateDif Average? Damn DateDif
    By UTCHELP in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 12-10-2012, 08:53 AM
  7. Replies: 1
    Last Post: 12-18-2007, 01:59 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