+ Reply to Thread
Results 1 to 6 of 6

Sorting Dates Column and calculating MTD, YTD

  1. #1
    Forum Contributor
    Join Date
    05-13-2009
    Location
    London, England
    MS-Off Ver
    Excel XP
    Posts
    174

    Sorting Dates Column and calculating MTD, YTD

    Hi guys,

    What I'm looking for is good ole fashioned formula-help on this one, no fancy-macro required unless you're feelin' generous hah.

    So Column 1 I've got dates, need to sort through that and calculate Year-to-date and Month-to-Date values. These are both Sums of the cells....
    YTD = Sum of all cells with most recent yr, in this case 2007
    MTD = Sum of all cells in Column B for most recent month, Feb2007 here.

    I've listed the desired solution for YTD and MTD on the sheet as well

    (I'm guessing the solution will have something to do with SUMPRODUCT?)
    Thanks in advance, i know its gonna be peanuts for some of you pros here
    Attached Files Attached Files
    Last edited by Pasha81; 11-10-2009 at 09:05 AM.

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Sorting Dates Column and calculating MTD, YTD

    try
    =SUMPRODUCT(--(YEAR($A$2:$A$500)=YEAR(MAX($A$2:$A$500))),B2:B500)
    and
    =SUMPRODUCT(--(YEAR($A$2:$A$500)=YEAR(MAX($A$2:$A$500))),--(MONTH($A$2:$A$500)=MONTH(MAX($A$2:$A$500))),B2:B500)
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Forum Contributor
    Join Date
    05-13-2009
    Location
    London, England
    MS-Off Ver
    Excel XP
    Posts
    174

    Re: Sorting Dates Column and calculating MTD, YTD

    Thanks alot Martin! Extremely Sorry about the delay in response. I just realised that I hadn't marked this thread as solved.
    Your formula is just what I needed
    Many Thanks

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

    Re: Sorting Dates Column and calculating MTD, YTD

    Given the data is sorted by date I don't think you really need to use SUMPRODUCT, you could achieve the same with SUMIF (& MAX etc...), eg:

    MTD:
    =SUMIF(A:A,">"&MAX(A:A)-DAY(MAX(A:A)),B:B)

    YTD:
    =SUMIF(A:A,">="&DATE(YEAR(MAX(A:A)),1,1),B:B)

  5. #5
    Forum Contributor
    Join Date
    05-13-2009
    Location
    London, England
    MS-Off Ver
    Excel XP
    Posts
    174

    Re: Sorting Dates Column and calculating MTD, YTD

    YEs you are correct Don, your method works as well
    Thanks, its easier to understand

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

    Re: Sorting Dates Column and calculating MTD, YTD

    If you want to get to grips with SUMPRODUCT see Bob Phillips' white paper on the function - linked in my sig., it's how I and many others I am sure learnt how to use it in the first instance.

    Regards SUMIF vs SUMPRODUCT - the former is significantly more efficient than the latter given the way in which each are processed (the latter is equiv. to an Array formula just without need for CSE)

+ 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