+ Reply to Thread
Results 1 to 8 of 8

Formula to Sum Last 4 Rows of Non-Zero Data

  1. #1
    Registered User
    Join Date
    11-15-2013
    Location
    Cincinnati, OH
    MS-Off Ver
    Excel 2010
    Posts
    3

    Formula to Sum Last 4 Rows of Non-Zero Data

    I have a large excel file that I update with weekly sales data, every week. I have a table that populates based off of a pivot table. We often look at key time periods other than just the last week (aka Last 4 Weeks, Last 8 Weeks, etc). So far, each week, I have been manually dragging the sum area down so it represents the last 4, 8, etc. weeks. For example (Where weeks 9 and 10 have not ocurred yet):


    Week $ Sales
    1 $100.00 L4 $2,300.00
    2 $200.00 L8 $3,300.00
    3 $300.00
    4 $400.00
    5 $500.00
    6 $600.00
    7 $600.00
    8 $600.00
    9 $0.00
    10 $0.00


    What formula can I add so that, when Week 9 occurs and the data gets added, the formula will automatically adjust to sum Weeks 6-9 (for L4) and 2-9 for L8? In essence, I need both the beginning value and the end value to be dynamic.


    Thanks to anyone who helps! I'm new to the thread, so if this has been discussed before, sorry!!

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Formula to Sum Last 4 Rows of Non-Zero Data

    one option:
    =SUM(INDIRECT("A" & LARGE(IF(NOT(A1:A100=""),ROW(A1:A100),0),1) & ":A" & LARGE(IF(NOT(A1:A100=""),ROW(A1:A100),0),4)))
    entered as an array formula (confirmed with ctrl+shift+enter)

  3. #3
    Registered User
    Join Date
    11-15-2013
    Location
    Cincinnati, OH
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Formula to Sum Last 4 Rows of Non-Zero Data

    When I try it with the data given, I get $1,234 for Weeks 5-8, instead of $2,300. Am I doing something wrong?

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Formula to Sum Last 4 Rows of Non-Zero Data

    It will count 0's as a value.

    Assuming that you will never have a week with 0 that you want to count, you would want:
    =SUM(INDIRECT("A" & LARGE(IF(A1:A100<>0,ROW(A1:A100),0),1) & ":A" & LARGE(IF(A1:A100<>0,ROW(A1:A100),0),4)))

  5. #5
    Valued Forum Contributor TheCman81's Avatar
    Join Date
    11-06-2012
    Location
    Edinburgh, UK
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    346

    Re: Formula to Sum Last 4 Rows of Non-Zero Data

    Does something liek this work for you?

    This is an array formula so needs to be entered with control shift enter

    shouse01 Test.xlsx
    Excel Guru in the making

    <----------If the question has been answered to your satisfication please click the Add Repuation star to the left

  6. #6
    Registered User
    Join Date
    11-15-2013
    Location
    Cincinnati, OH
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Formula to Sum Last 4 Rows of Non-Zero Data

    THAT WORKED! THANK YOU! Haha..... new issue now. We often compare to weekly sales from the prior year. Since all weeks have completed and have values, how do I sum the same rows that are summed in the current year's data? i.e. If I had column C where values for all 10 weeks were entered, how would I sum the same rows (Weeks 5-8) as the previous calculation?
    Last edited by shouse01; 11-15-2013 at 12:50 PM.

  7. #7
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Formula to Sum Last 4 Rows of Non-Zero Data

    In the formula I gave you, change "A" to whatever column you wish. So for column C:
    =SUM(INDIRECT("C" & LARGE(IF(A1:A100<>0,ROW(A1:A100),0),1) & ":C" & LARGE(IF(A1:A100<>0,ROW(A1:A100),0),4)))

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

    Re: Formula to Sum Last 4 Rows of Non-Zero Data

    =sum(index($b$10000:index($b$2:$b$10000,large(index(($b$2:$b$10000<>0)*row($b$1:$b$9999),0),4)),0)) last 4
    =sum(index($b$10000:index($b$2:$b$10000,large(index(($b$2:$b$10000<>0)*row($b$1:$b$9999),0),8)),0)) last 8
    "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

+ 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. Copy formula that spans several rows of data
    By acmichae in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-08-2013, 01:50 PM
  2. Formula populates 2 rows after data set
    By mivital in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-11-2008, 09:57 AM
  3. macro - autofill formula to end of data rows
    By ugg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-29-2007, 04:16 AM
  4. What formula captures specified rows of data?
    By Brian G Scully in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-28-2005, 10:20 AM
  5. [SOLVED] Inserting rows with Data, Formula's and Validation
    By Doug Manning in forum Excel General
    Replies: 0
    Last Post: 09-16-2005, 08:05 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