+ Reply to Thread
Results 1 to 11 of 11

Using the SUM function to record weekly sales

Hybrid View

  1. #1
    Registered User
    Join Date
    11-14-2007
    Posts
    39

    Using the SUM function to record weekly sales

    I would like to have a set of cells that add up all the sales within a given week. I know how to do this simply for one week, but how do I get Excel to automatically take this function and create the rest for future weeks? After entering the SUM function in one cell, I click and drag on the box to try to get Excel to correctly input the functions in the next cells (like how Excel will correctly input the next date, week, or month). But Excel doesn't do it correctly.

    Thanks for the help!

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Using the SUM function to record weekly sales

    How about posting:
    1) some sample data
    2) what you want to achieve
    3) what you've tried that hasn't worked (eg your formula)

    That way you'll get responses that are tailored to fit your situation.
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Registered User
    Join Date
    11-14-2007
    Posts
    39
    Okay, for example:

    Box 1: 9, 4, 3, 2, 9, 0, 8, 3, 0, 1, 4, 5, 7, 2, 4, 3, 7, 2, 5, 6, 5
    Box 2: 3, 3, 3, 5, 6, 2, 9, 0, 6, 7, 4, 4, 2, 5, 2, 1, 0, 4, 6, 3, 4

    So let's imagine that the data above refers to the number of boxes sold of each type each day. For reference, let's say the first piece of data after Box 1 (9) is cell B1

    So I enter: =SUM(B1:H2) in order to add all the sales for the first seven days.

    I now want the same function performed, but for the following week. I could manually enter the formula =Sum(I1:O2), but I am hoping there is a way to get Excel to automatically recognize that this is what I want to do, in the same way that you can enter a single date and then click the black surrounding box and drag to have the adjacent cells populated with the following dates. When I try this click and drag approach for totally the sales by week, the adjacent cell is populated with the follwing formula (using our example data): =SUM(C1:J2). This is adding up seven days of sales, but it does not begin where the previous formula left off. I have also tried manually entering the formulas in two adjacent cells (i.e. one cell has =SUM(B1:H2) and the one to its right has =SUM(I1:O2)). This does not work either.

    Thanks for the help.

  4. #4
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Using the SUM function to record weekly sales

    Since you're copying the formula to the right....
    try this:

    Enter this formula wherever you want it:
    =SUMPRODUCT((CEILING((COLUMN($B:$V)-COLUMNS($A:$A))/7,1)=COLUMNS($A:A))*$B$1:$V$2)
    
    or...this shorter version with a "hardcoded" offset:
    =SUMPRODUCT((CEILING((COLUMN($B:$V)-1)/7,1)=COLUMNS($A:A))*$B$1:$V$2)
    Copy it across to the right.
    ADDITIONAL COMMENTS:
    The shortest method would be to use the OFFSET function, but that is a volatile function, meaning that it recalculates whenever the workbook calculates anything. Consequently, volatile functions can degrade calculation performance, resulting in sluggish workbooks.

    If you happen to prefer the OFFSET approach....here's one utilization:
    =SUM(OFFSET($A$1:$A$2,0,((COLUMNS($A:A)-1)*7)+1,2,7))
    Is that something you can work with?
    Last edited by Ron Coderre; 11-14-2007 at 01:52 PM.

  5. #5
    Registered User
    Join Date
    11-14-2007
    Posts
    39
    I tried out the very first formula you posted and that seems to work correctly. However, the cell letters and numbers I am really using (as opposed to those in the example) are different and I can't quite figure out how to adapt the formula specifically for my needs. The groups of cells that I need summed are as follows:

    F3:L6
    M4:S6
    etc.

    I'm hoping that if you tell me exactly how to stick those cell ranges into the first formula you provided I'll be able to adapt the formula whenever necessary.

    Thanks a lot for your help!!!

  6. #6
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Using the SUM function to record weekly sales

    Sure thing.

    Let's start with the original formula:
    =SUMPRODUCT((CEILING((COLUMN($B:$V)-COLUMNS($A:$A))/7,1)=COLUMNS($A:A))*$B$1:$V$2)
    
    Here's what it does...
    
    PART I: Which columns do I want values from?
    This section: COLUMN($B:$V)-COLUMNS($A:$A)
    1) calculates the column numbers of columns B through V. {2,3,4...,22}
    and
    2) subtracts the number of columns before that range (one, in this instance)
    returning {1,2,3,4...,21}
    
    Then we divide each of those numbers by 7
    BUT, we use the CEILING function to force all fractional values UP to the
    next multiple of 1.
    1/7= 0.142857142857143....becomes 1
    2/7= 0.285714285714286....becomes 1
    8/7= 1.14285714285714....becomes 2
    etc
    
    So, now we can assign each column to a specific 7-day period
    
    Next, this part: COLUMNS($A:A)
    calculates which 7-day period I want values from.  
    
    If the formula is in Col_B...that section returns 1.
    When it's copied to Col_D...that section returns 3.
    
    When combined with the CEILING section, the verbal version of that section 
    is: Check each column in the data range. Is it in the week I want?
    A series of TRUE and FALSE values are returned. 
    7 of them will be TRUE; all the others will be FALSE.
    
    When TRUE and FALSE are used in arithmetic equations, Excel converts them 
    to 1 and 0, respectively.
    
    PART II: What's the total of the cells in the columns I want values from?
    Each cell in the data area is multiplied by the 1 or 0 assigned to it in PART I. 
    The end result is an array containing numbers from the cells in the week 
    I care about and zeros for the cells in the other weeks.
    
    The SUMPRODUCT function adds them all up. 
    
    NOW....LETS CHANGE THE FORMULA TO SUIT THE NEW DATA RANGE
    
    Starting with:
    =SUMPRODUCT((CEILING((COLUMN($B:$V)-COLUMNS($A:$A))/7,1)=COLUMNS($A:A))*$B$1:$V$2)
    
    1) We change the column identification references 
    from this: COLUMN($B:$V) to this: COLUMN($F:$Z)
    
    2) We change the negative adjustment references 
    from this: COLUMNS($A:$A) to this: COLUMNS($A:$E)
    (so we're subtracting 5 from the column number, insted of 1.)
    
    3) We change the data range references 
    from this: $B$1:$V$2 to this: $F$1:$Z$2
    
    NOTE: we leave this section intact: =COLUMNS($A:A)
    because it counts weeks for us.
    
    The end result is this formula:
    =SUMPRODUCT((CEILING((COLUMN($F:$Z)-COLUMNS($A:$E))/7,1)=COLUMNS($A:A))*$F$1:$Z$2)
    I hope that helps.
    Post back if you have more questions.
    Last edited by Ron Coderre; 11-14-2007 at 04:24 PM.

+ 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