+ Reply to Thread
Results 1 to 7 of 7

Need formula to calculate YTD variance of current and prior year

  1. #1
    Forum Contributor
    Join Date
    04-27-2009
    Location
    Dallas, TX
    MS-Off Ver
    Office 365
    Posts
    215

    Need formula to calculate YTD variance of current and prior year

    I'm building a spreadsheet where I have 3 variances that I am concerned with:

    1. Current Month Better/(Worse) Prior Month - I use an offset formula to look at the two specific columns
    2. Current Month Better/(Worse) Prior Year - I use the same formula as above but point to the same month in the previous year
    3. Current Month Year-to-Date Better/(Worse) Prior Year-to-Date

    It is this third formula that I am having trouble with. Currently I copy the current month column and insert to the left. That column does a vLookup on another sheet to get the correct values. I need the YTD variance column to continually grow each month so that it captures Jan to May 2014 less Jan to May 2013. Then the next month as I insert the new month's column I need that formula to "automatically" update to calculate Jan to Jun 2014 less Jan to Jun 2013.

    Cell A1 has the first day of the current month so I was thinking of using the "Month" formula to convert that to a growing variable which equates to the number of columns to use. Then use that in conjunction with the offset formula. But I'm not sure how to do this. I've attached a sample spreadsheet to assist you. Thanks in advance!
    Attached Files Attached Files
    Last edited by mvparker79; 06-25-2014 at 03:49 PM. Reason: Solved

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Need formula to calculate YTD variance of current and prior year

    Try these...

    C4=SUMPRODUCT(($G4:$W4)*(YEAR($G$3:$W$3)=YEAR($A$1)-1)*(MONTH($G$3:$W$3)<=MONTH($A$1)))-SUMPRODUCT(($G4:$W4)*(YEAR($G$3:$W$3)=YEAR($A$1)))
    (Might have that 1 swapped around?)
    D4=INDEX($G4:$W4,MATCH(EDATE($A$1,-12),$G$3:$W$3,0))-INDEX($G4:$W4,MATCH($A$1,$G$3:$W$3,0))
    E4=INDEX($G4:$W4,MATCH(EDATE($A$1,-1),$G$3:$W$3,0))-INDEX($G4:$W4,MATCH($A$1,$G$3:$W$3,0))

    With these, you wont need to fiddle with the offset values each month, they will update automatically when you change the date in A1
    Last edited by FDibbins; 06-25-2014 at 03:33 PM. Reason: corrected a typo...F4 to E4
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Contributor
    Join Date
    04-27-2009
    Location
    Dallas, TX
    MS-Off Ver
    Office 365
    Posts
    215

    Re: Need formula to calculate YTD variance of current and prior year

    Looks great! Now I need to dissect it and figure out what each step is doing.

  4. #4
    Registered User
    Join Date
    06-22-2014
    Location
    India
    MS-Off Ver
    2010
    Posts
    8

    Re: Need formula to calculate YTD variance of current and prior year

    Hi,

    Please see the attached file, I have used INDEX & MATCH functions to achieve this after slightly modifying the data layout.
    Attached Files Attached Files

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Need formula to calculate YTD variance of current and prior year

    Basic formula is this...
    INDEX($G4:$W4,MATCH($A$1,$G$3:$W$3,0))

    INDEX() gives the range - in this case that row of data
    MATCH() finds which column to look in
    find the column that the date in A1 is in
    the EDATE() part calcs the date based on a given date (A1) x-months from then, so I used -12 to go back 1 year

    =SUMPRODUCT(($G4:$W4)*(YEAR($G$3:$W$3)=YEAR($A$1)-1)*(MONTH($G$3:$W$3)<=MONTH($A$1)))

    this is adding all values in the row ($G4:$W4) that meet your criteria...
    (YEAR($G$3:$W$3)=YEAR($A$1)-1) the year = 2014-1=2013
    (MONTH($G$3:$W$3)<=MONTH($A$1) the mont this <= the month in A1

  6. #6
    Forum Contributor
    Join Date
    04-27-2009
    Location
    Dallas, TX
    MS-Off Ver
    Office 365
    Posts
    215

    Re: Need formula to calculate YTD variance of current and prior year

    Thanks for all your help guys. I received FDibbins reply first so I've already incorporated it in to my spreadsheet. Looks like it is going to work like a charm!

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Need formula to calculate YTD variance of current and prior year

    Glad it worked for you

+ 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. Replies: 2
    Last Post: 03-14-2014, 08:47 PM
  2. Formula to calculate the current policy year.
    By mbecker4 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-24-2012, 01:38 PM
  3. Calculate Sum of Range for current year
    By Frozen001 in forum Excel General
    Replies: 3
    Last Post: 08-10-2010, 12:26 PM
  4. [SOLVED] Cells w/Date Formats should know when to use current/prior year
    By Donna Fernandez in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-01-2005, 04:25 PM
  5. How to compare current year to prior year in bar chart?
    By substring in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 05-12-2005, 02: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