+ Reply to Thread
Results 1 to 7 of 7

Summing products in spaced columns

  1. #1
    Registered User
    Join Date
    07-24-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2007
    Posts
    7

    Summing products in spaced columns

    I'm sure the following is possible, but cant quite figure it out... Say theres 3 column headings, repeated across columns multiple times. There are multiple rows of data, and I am trying to create a summary statistic for each row. The longhand calculation I need to do is A3*B3/$A$1 + D3*E3/$A$1 + G3*H3/$A$1 + ... for however many columns I have. The first column heading data (columns A, D, G...) is just a number, as is the second heading (columns B, E, H...). $A$1 is the sum of all the second heading values (B3+E3+H3+...).
    One way to get the value for $A$1 is {=SUM((MOD(COLUMN(B3:L3)-COLUMN(B3),3)=0)*(B3:L3))}, where column L is the end of the range of interest (and is actually more like column ED, hence I dont want to do the longhand).
    I sense this should be possible with SUMPRODUCT, but suspect one of my problems is that the above sum only works as an array formula, which I cant make work with the SumProduct.

    Anyways, can anyone tell me how to achieve this with or without the SUM and SumProduct functions, such that I can easily generate the summary statistic? As well as there being many additions to make longhand, I also need to make several different summary statistics so it would take ages.

    Example data attached.

    Thanks, jsw
    Attached Files Attached Files

  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,942

    Re: Summing products in spaced columns

    Looking at your data (and calcs) what exactlty are you trying to achieve here?

    It *looks* like you are taking a mean * the qty used to get that mean, and then dividing that by the total values...and then adding up all all of those answers?

    If thats what you are doing, I have a feeling your basic concept is flawed. Using your sample data, you are expecting an answer of +12...but the highest of any individual calc is 6.6?
    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 Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Summing products in spaced columns

    well a1 can just be
    =SUMIF(A2:L2,"counts",A3:L3)
    and you can offset sum product
    =SUMPRODUCT(--(MOD(COLUMN(A3:L3),3)=1),A3:L3,--(MOD(COLUMN(B3:M3),3)=2),B3:M3)/SUMIF(A2:L2,"counts",A3:L3)
    gives answer of 12.94444444
    Last edited by martindwilson; 08-11-2013 at 07:18 PM.
    "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

  4. #4
    Registered User
    Join Date
    07-24-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Summing products in spaced columns

    Hello,
    The calc is averaging a bunch of averages, but because the data is calculated from discrete values, a weighting is required for each of the data. You could think of each set of three columns as being data from a month, for example, where the average 10 (e.g. col A) is derived from e.g. 3 data points (col B) in January. If I included 12 months of data, simply averaging the 12 averages in this situation does not give the correct answer (i.e. does not give the same answer as if I took all the raw data and averaged it); weighting by the number of data points in each month does. Hope that makes sense?

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

    Re: Summing products in spaced columns

    see my last post

  6. #6
    Registered User
    Join Date
    07-24-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Summing products in spaced columns

    Beautiful, Thank you Mr Wilson. Very much appreciated. Once question about your solution - the second array is offset by one column (B:M) - I understand that the array needs to be the same size as the others, A:L, however what prevents the slightly modified solution below from working (second array in SumProduct)? Must the first element in the returned array be a 'hit', which is achieved by using B:M but not A:L?
    =SUMPRODUCT(--(MOD(COLUMN(A3:L3),3)=1),A3:L3,--(MOD(COLUMN(A3:L3),3)=2),A3:L3)/SUMIF(A2:L2,"counts",A3:L3)
    Thanks again for your help, jsw

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

    Re: Summing products in spaced columns

    they have to line up so all the trues go together or the answer would be 0
    --(MOD(COLUMN(A3:L3),3)=1),A3:L3,--(MOD(COLUMN(A3:L3),3)=2) would cancel each other out as both couldn't be true
    ie mod(COLUMN(A3),3)=1 would be true but mod(COLUMN(A3),3)=2 would be false
    sumproduct would give 1(true) *0(false)=0
    Attached Files Attached Files
    Last edited by martindwilson; 08-11-2013 at 08:43 PM.

+ 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] Inconsistent spaced data that I need parsed into separate columns
    By dklesper2012 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-10-2013, 04:01 PM
  2. #VALUE! when summing the products of two column
    By arki in forum Excel General
    Replies: 4
    Last Post: 06-14-2011, 02:11 AM
  3. Replies: 3
    Last Post: 09-24-2008, 11:12 AM
  4. [SOLVED] chart ledgend looks double spaced. How do I fix to single spaced?
    By villalp in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 04-25-2006, 02:20 PM
  5. [SOLVED] Need help summing the total of two columns with their products
    By mike_vr in forum Excel General
    Replies: 3
    Last Post: 12-16-2005, 12:10 PM

Tags for this Thread

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