+ Reply to Thread
Results 1 to 16 of 16

Formula to sum every 2 columns based on criteria found in previous column

  1. #1
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Formula to sum every 2 columns based on criteria found in previous column

    Hi,

    How can I sum multiple columns based on criteria found in adjacent value in single step? Please see attached.

    Thank you in advance,
    Paul
    Attached Files Attached Files

  2. #2
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,496

    Re: Formula to sum every 2 columns based on criteria found in previous column

    If I'm understanding your request correctly, this would be one way...
    =SUMPRODUCT($B$1:$B$21,--(MONTH($A$1:$A$21)=$H2))+SUMPRODUCT($D$1:$D$21,--(MONTH($C$1:$C$21)=$H2))+SUMPRODUCT($F$1:$F$21,--(MONTH($E$1:$E$21)=$H2))
    just combining the three sumproducts.
    Make contributors happy, click on the "* Add Reputation" as a way to say thank you.
    Sam Capricci

  3. #3
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Formula to sum every 2 columns based on criteria found in previous column

    I thought so, but I have 60 columns under the same format. Is there a way to keep it simple or I have to write a sumproduct for each one?

  4. #4
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,496

    Re: Formula to sum every 2 columns based on criteria found in previous column

    Is there a reason you have 60 columns under the same format? I mean, if what you posted had everything going down columns A and B instead of A and B, C and D and E and F then you could use a simple single sumproduct like this...
    =SUMPRODUCT($B$1:$B$63,--(MONTH($A$1:$A$63)=$H2))
    or even this
    =SUMPRODUCT($B$1:$B$63,--(MONTH($A$1:$A$63)=ROW(A1)))
    then you don't need the helper column of numbers in H2:H13.

  5. #5
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Formula to sum every 2 columns based on criteria found in previous column

    The thing is that this is part of a bigger report set on a specific format, requested. Therefore, it cannot be changed. That is my biggest issue

  6. #6
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,496

    Re: Formula to sum every 2 columns based on criteria found in previous column

    Hmmm, if you have 60 columns of data which can't be altered (30 of dates and 30 of numbers) I'm having trouble of figuring out a way to do it without 30 sumproducts other than maybe in a pivot table but I'm still not sure that will work without some type of consolidation.
    Maybe someone else will stop by with a better recommendation.

  7. #7
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Cool Re: Formula to sum every 2 columns based on criteria found in previous column

    try to group dates by month and sum appropriate values. this is a shi...ty job but...

    in your example i see only 10 months, so... using PowerQuery:


    Date Sum
    1
    217
    2
    455
    3
    121
    4
    26
    5
    161
    6
    678
    7
    1387
    8
    333
    9
    441
    10
    171
    Last edited by sandy666; 06-29-2018 at 12:32 PM.

  8. #8
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,814

    Re: Formula to sum every 2 columns based on criteria found in previous column

    I expect that something based on a pivot table will be much easier to use -- especially long term. I:

    1) Copied C,D and E,F and pasted them beneath the existing data in A,B to get a single list of data.
    2) Added a row at the top and entered row headers ("date" in A1 and "values" in B1)
    3) Insert -> pivot table
    4) Make date the row labels and sum of value the values field.
    5) Select the dates column in the pivot table and group by month.

    I also added another column with "a" for the original set of data in A,B; "b" for the data originally in C,D; and "c" for the data originally in E,F. I expect there is some reason the data exist in three columns, so this additional column will allow other pivot tables to recapture the three different "types" of data.

    Unless there is some significant reason to not use pivot tables and other database tools, this looks like database work and, in the long run, will be easiest to manage if you set the original data up into a good database format. See recent discussion (along with some good links to other sites) here: https://www.excelforum.com/excel-new...ta-layout.html
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  9. #9
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Formula to sum every 2 columns based on criteria found in previous column

    If you still want a single formula method this is fairly convoluted. It requires some array coercion. It must be array entered.

    If you aren’t familiar with array-entered formulas array enter means the formula must be committed from edit mode by simultaneously pressing and holding down Ctrl and Shift while hitting Enter.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    If you wish to eliminate the nested IFERROR cut the column references in half ... ie COLUMN($A$1:$F$1) to COLUMN($A$1:$C$1).

    Like this ... still array entered.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Dave

  10. #10
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Formula to sum every 2 columns based on criteria found in previous column

    I'd like to see example with all columns & cutted rows to eg. 100 - if it's possible (or whole data - desensitized of course )

  11. #11
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Formula to sum every 2 columns based on criteria found in previous column

    How about something on the lines of

    =SUMIFS($B$1:$F$21,$A$1:$E$21,">="&DATE(2018,H2,1),$A$1:$E$21,"<="&EOMONTH(DATE(2018,H2,1),0))

    Of course, this assumes that no single cell in the columns to be summed will contain values high enough to be incorrectly evaluated as date serial numbers. (43101 to 43465 for 2018).
    Last edited by jason.b75; 06-30-2018 at 04:01 AM.

  12. #12
    Forum Contributor Gregor y's Avatar
    Join Date
    10-24-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2010 32-Bit
    Posts
    276

    Re: Formula to sum every 2 columns based on criteria found in previous column

    just to throw my hat in the ring, incase you're still looking for a single SUMPRODUCT formula

    in Cell L2:
    =SUMPRODUCT($B$1:$F$21*(MOD(COLUMN($B$1:$F$21),2)=0)*(MONTH($A$1:$E$21)=H2)*(MOD(COLUMN($A$1:$E$21),2)=1))
    Last edited by Gregor y; 06-29-2018 at 09:01 PM. Reason: reduce leftover ()'s
    If it'd make you feel better using my answer because of my street cred, then you can go ahead and click Add Reputation below to improve it.

  13. #13
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,901

    Re: Formula to sum every 2 columns based on criteria found in previous column

    Try this:

    =SUMPRODUCT(ISODD(COLUMN($A$1:$E$21))*(MONTH($A$1:$E$21)=$H2),$B$1:$F$21)

  14. #14
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Cool Re: Formula to sum every 2 columns based on criteria found in previous column

    Just for fun I did 20 columns test and Phuocam's formula works perfectly (as mine PQ also )
    I'm too lazy to generate more columns and data
    Attached Files Attached Files

  15. #15
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Formula to sum every 2 columns based on criteria found in previous column

    Thank you all for all the solution provided.

  16. #16
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Formula to sum every 2 columns based on criteria found in previous column

    You are welcome, Use POWER Query, Luke
    Thanks for the feedback
    Have a nice day
    Last edited by sandy666; 07-02-2018 at 05:11 AM.

+ 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: 05-27-2018, 09:43 AM
  2. [SOLVED] Formula to Sum Multiple Columns Based on Column Headings and Other Criteria
    By webfeet2 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-10-2015, 12:20 PM
  3. [SOLVED] Return value from 1st Column based on Data found in corresponding Columns
    By jahtrini in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-12-2013, 03:51 PM
  4. Correct formula for adding columns based on previous row
    By packers316 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 08-02-2013, 06:44 AM
  5. [SOLVED] Unhide columns based on the previous column's value
    By dumbom in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-07-2012, 08:20 AM
  6. Replies: 10
    Last Post: 04-27-2010, 11:31 AM
  7. Finding Avg. Based on Criteria Found in a Second Column
    By Alhazred in forum Excel General
    Replies: 5
    Last Post: 02-07-2008, 04:17 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