+ Reply to Thread
Results 1 to 21 of 21

Sum column based on values in 2 other columns

  1. #1
    Registered User
    Join Date
    12-10-2021
    Location
    NS, Canada
    MS-Off Ver
    2016
    Posts
    7

    Sum column based on values in 2 other columns

    Looking for a formula that would sum a column based on Values in 2 other columns

    Column A is a name, Column B is if there are any errors, could be blank or any numerical value, and Column C is a case amount, a numerical value. I would like to sum Column C for "Mike" in Column A until there is an error in Column B, and not include that value in Column C for the row that the error occurred in the summation.

    Thanks so much!

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,274

    Re: Sum column based on values in 2 other columns

    I would like to sum Column C for "Mike" in Column A until there is an error in Column B,
    An Error for Mike only or any error? And if Mike / valid B / value in C occurs after the error, should it be included with Mike's total?
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    12-10-2021
    Location
    NS, Canada
    MS-Off Ver
    2016
    Posts
    7

    Re: Sum column based on values in 2 other columns

    Error for Mike only,there will be many names that I will copy the formula to and track for each person. I don't want to include any value in C for the row of the error or after the error. What I am trying to do is calculate a running total until an error occurs in Colum B. I want to be able to look and see how many cases each person has since their last error. Each new row will go at the top, so it will be looking top down for the most recent error, and adding colum C to that point.

  4. #4
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 365 version 2501
    Posts
    18,893

    Re: Sum column based on values in 2 other columns

    Please read the yellow banner at the top of this page on how to attach an Excel file.
    Let us know if you have any questions.
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  5. #5
    Registered User
    Join Date
    12-10-2021
    Location
    NS, Canada
    MS-Off Ver
    2016
    Posts
    7

    Re: Sum column based on values in 2 other columns

    In the attachment, want to sum cases up to the latest error, which will always be top down with most recent at top. In this case want the three case values that equal 581. Do not want to include the value for the row that had the error.
    Attached Files Attached Files

  6. #6
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Sum column based on values in 2 other columns

    A guess, as you did not show how/where you wanted the results presented.

    =SUMIF(A2:INDEX($A2:$A$23,MATCH(1,($A$2:$A$23=F2)*($B$2:$B$23=1),0)-1),F2,C2:INDEX($C$2:$C$23,MATCH(1,($A$2:$A$23=F2)*($B$2:$B$23=1),0)-1))

    see sheet.
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  7. #7
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,274

    Re: Sum column based on values in 2 other columns

    With your list of assemblers starting in G2, array-enter (enter using Ctrl-Shift-Enter)

    =IFERROR(SUMPRODUCT(($C$2:$C$23)*($A$2:$A$23=G2)*(ROW($C$2:$C$23)<(MATCH(G2&"1",$A$1:$A$23&$B$1:$B$23,FALSE)))),SUMIF(A:A,G2,C:C))

    And copy down to match your assemblers list, as in the attached.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    12-10-2021
    Location
    NS, Canada
    MS-Off Ver
    2016
    Posts
    7

    Re: Sum column based on values in 2 other columns

    Thanks for both those options,as I'll be adding a column on a sheet I think Bernie's works best. My question is, the error column could be any number, it would need to work when that error value in column B is a 2, or a 10, or any value. How do I adjust the formula to accommodate that?

    Thanks for the help!

  9. #9
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Sum column based on values in 2 other columns

    If I understand you correctly... a tiny tweak:

    see file
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    12-10-2021
    Location
    NS, Canada
    MS-Off Ver
    2016
    Posts
    7

    Re: Sum column based on values in 2 other columns

    Doesn't look like that one is working, shows correct for Mike, but it should show 144 for Dan, shows nothing. And for Chuck it shows 313, but should show just 233 as he made an error on the second one that had the 80 cases.

  11. #11
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,768

    Re: Sum column based on values in 2 other columns

    Try

    =SUM(SUMIFS($C$2:$C$23,$A$2:$A$23,G2,$B$2:$B$23,{"",0}))
    Attached Files Attached Files
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  12. #12
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,274

    Re: Sum column based on values in 2 other columns

    Array-enter this in my cell H2, using Ctrl-Shift-Enter:

    =IFERROR(SUMPRODUCT(($C$2:$C$23)*($A$2:$A$23=G2)*(ROW($C$2:$C$23)<(1/(1/MIN(IF($A$2:$A$23=G2,IF($B$2:$B$23>0,ROW($B$2:$B$23)))))))),SUMIF(A:A,G2,C:C))

  13. #13
    Registered User
    Join Date
    12-10-2021
    Location
    NS, Canada
    MS-Off Ver
    2016
    Posts
    7

    Re: Sum column based on values in 2 other columns

    That worked. Last question, I hope. This list will grow each week, it looks like the sum of Cases grows as I add lines for each person, but it doesn't respect the errors in column B. I tried changing formula to the entire column instead of just to row 23 but that didn't work. Is that possible, or should I just update the formula to the exact row each time?
    Thanks

  14. #14
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,274

    Re: Sum column based on values in 2 other columns

    Insert new rows into your used range, and the formula will expand. You cannot use entire columnw with array formulas.

  15. #15
    Registered User
    Join Date
    12-10-2021
    Location
    NS, Canada
    MS-Off Ver
    2016
    Posts
    7

    Re: Sum column based on values in 2 other columns

    Perfect, that's great, thanks again

  16. #16
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,768

    Re: Sum column based on values in 2 other columns

    The SUMIFS in post #11 gives the same result as Bernie's formula: am I missing something?

  17. #17
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,274

    Re: Sum column based on values in 2 other columns

    Your formula fails if there are 0 or blank values in B, in lower rows for the same names that have errors up higher. The values from C get added to the total for those rows.
    Last edited by Bernie Deitrick; 12-15-2021 at 04:31 PM.

  18. #18
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,768

    Re: Sum column based on values in 2 other columns

    In attached column H & I results are identical ????
    Attached Files Attached Files

  19. #19
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,274

    Re: Sum column based on values in 2 other columns

    Simplified name list - lots of "Mike" entries. The OP described in words what he wanted, but his data set didn't reflect the 'reset' that he expected.
    Attached Files Attached Files

  20. #20
    Forum Expert wk9128's Avatar
    Join Date
    08-15-2020
    Location
    China Shanghai
    MS-Off Ver
    365 V2502 and WPS V2024(12.1.0.18543)
    Posts
    3,866

    Re: Sum column based on values in 2 other columns

    Borrow POST#19 Bernie Deitrick'S attachment file

    Another way

    Cell J2 formula , drag down

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

  21. #21
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,274

    Re: Sum column based on values in 2 other columns

    This formula also fails if there are 0 or blank values in B, in lower rows for the same names that have errors up higher. The values from C get added to the total for those rows.

+ 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. VBA - Creating new column (Columns M) with values based on previous column (Column L)
    By will12321 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-21-2020, 03:36 AM
  2. [SOLVED] Match Values Based on First Column then Between Values in Next Two Columns
    By ntsun in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-04-2017, 10:06 AM
  3. [SOLVED] Concatenating values two columns (column B, column C) based on criterion
    By marreco in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-16-2014, 11:31 AM
  4. Count Unique values in Column based on values in other columns
    By dmschave in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-17-2014, 11:06 AM
  5. Replies: 1
    Last Post: 11-16-2013, 05:18 AM
  6. [SOLVED] Sum values in column based on variable values in 3 other columns
    By Winon in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-03-2012, 10:13 AM
  7. SUMIF - add values from one column based on values in two other columns
    By goodmike in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-30-2008, 08:04 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