SUMIF multiple columns with one or several criteria in Excel

This tutorial will teach you a few easy ways to sum multiple columns in Excel based on a single or multiple criteria.

Doing a conditional sum in Excel is a piece of cake as long as all the values to be totaled are in one column. Summing multiple columns is a problem because both the SUMIF and SUMIFS functions require the sum range and criteria ranges to be equally sized. Luckily, when there is no straight way to do something, there is always a work-around :)

Excel Sum If: multiple columns, single criterion

First off, let's get to know exactly what problem we are trying to solve. Suppose you have a table of monthly sales like shown below. Because it was consolidated from a number of regional reports, there are a few records for the same product:
Source data

The question is - how do you get a total of sales for a certain item?

The first idea that comes to mind is using a SUMIF formula in its pure form:

=SUMIF(A2:A10, "apples", C2:E10)

Unfortunately, this won't work. The reason is that the dimensions of sum_range are determined by Excel automatically based on the dimensions of the range argument. As our criteria range includes only one column (A2:A10), so does the sum range (C2:C10). The sum_range parameter defined in the formula (C2:E10) actually determines only the upper left cell of the range that will be summed. As a result, the above formula will add up the apples sales only in column C. Not what we are looking for, eh?

The simplest working solution that suggests itself is to create a helper column summing the numbers for each individual row, and then use that column for sum_range.

So, go ahead and place a SUM formula in F2, then drag it down across as many cells as needed:

=SUM(C2:E2)

After that, you can quickly have the job done:

=SUMIF(A2:A10, I1, F2:F10)

Where I1 is the item of interest.

In the above formula, sum_range is of the same size as range (1 column and 9 rows), so it works without a hitch:
Adding a helper column to sum multiple columns with a condition

If the layout of your worksheet does not have room for any extra columns, then apply one of the following solutions.

SUMIF multiple columns

The idea is to write a separate SUMIF formula for each of the columns you want to sum, and then add up the results:

SUM(SUMIF(…), SUMIF(…), SUMIF(…))

Or

SUMIF(…) + SUMIF(…) + SUMIF(…)

A practical implementation looks as follows:

=SUM(SUMIF(A2:A10,H1,C2:C10), SUMIF(A2:A10,H1,D2:D10), SUMIF(A2:A10,H1,E2:E10))

Or

=SUMIF(A2:A10, H1, C2:C10) + SUMIF(A2:A10, H1, D2:D10) + SUMIF(A2:A10, H1, E2:E10)

You can also "hardcode" the condition in the formula if needed:

=SUMIF(A2:A10, "Apples", C2:C10) + SUMIF(A2:A10, "Apples", D2:D10) + SUMIF(A2:A10, "Apples", E2:E10)

SUMIF formula for multiple columns

This works fine for a reasonable number of columns, but for a large dataset the formula becomes too long and difficult to read. In this case, the below solutions are more appropriate.

SUM as array formula

Another way to do a sum if in multiple columns based on one criterion is to construct an array formula:

SUM((sum_range) * (--(criteria_range=criteria)))

For our sample dataset, the formula takes this form:

=SUM((C2:E10)*(--(A2:A10=H1)))

Or

=SUM((C2:E10)*(--(A2:A10="Apples")))

In Excel 2019 and older, you should press Ctrl + Shift + Enter to complete the formula correctly. In Excel 365 and Excel 2021, this works as a normal formula due to inbuilt support for dynamic arrays.
Conditionally sum multiple columns

How this formula works:

The core concept is to multiply the elements of these two arrays:

  • (C2:E10) - all the values in the sum range. In our case, the array contains 27 elements (3 columns and 9 rows: {250,120,210;155,180,210;130,175,125; …}
  • (--(A2:A10=H1)) - compares each value in A2:A10 against the target item in H1. The result is an array of TRUE (the condition is met) and FALSE (the condition is not met) values, which is then converted into an array of 1's and 0's with the help of a double unary operator: {0;1;0;0;1;0;0;1;1}

Please pay attention that the first array is two-dimensional (each column of data is separated by a comma and each row by a semicolon) and the second one is a one-dimensional vertical array (1 column of data, rows are separated by semicolons). When the two arrays are multiplied, all the items of the 2D array in a given row are multiplied by the corresponding element of the 1D array:
Multiplying the items of two arrays

As multiplying by zero gives zero, only the numbers for which the criterion is TRUE survive, and the SUM function adds them up:

=SUM({0,0,0;155,180,210;0,0,0;0,0,0;160,140,170;0,0,0;0,0,0;…})

To make the formula's logic easier to understand, you can write the first multiplier in this way:

=SUM((C2:C10 + D2:D10 + E2:E10) * (--(A2:A10=H1)))

This will produce an array of sums by row (like the helper column does in the very first example), which is then multiplied by an array of 1's and 0's:

{580;545;430;615;470;750;550;620;570}*{0;1;0;0;1;0;0;1;1}

The result of multiplication is served to SUM:

=SUM({0;545;0;0;470;0;0;620;570})

Don't like using arrays formulas in your sheet? Neither do I. Well, let's go check the next solution :)

SUMPRODUCT formula

The strategy described in the above example can also be implemented using the SUMPRODUCT function.

SUMPRODUCT((sum_range) * (criteria_range=criteria))

A real-life formula goes as follows:

=SUMPRODUCT((C2:E10) * (A2:A10=H1))

The formula's logic is the same as in the previous example. The beauty of the SUMPRODUCT function is that it supports arrays natively, so it works nicely as a regular formula in all Excel versions.
SUMPRODUCT formula to sum multiple columns based on condition

Excel Sum If: multiple columns, multiple criteria

The three approaches we utilized to add up multiple columns with one criterion will also work for conditional sum with multiple criteria. The formulas will just become a little more complex.

SUMIFS + SUMIFS to sum multiple columns

To sum cells that match multiple criteria, you normally use the SUMIFS function. The problem is that, just like its single-criterion counterpart, SUMIFS doesn't support a multi-column sum range. To overcome this, we write a few SUMIFS, one per each column in the sum range:

SUM(SUMIFS(…), SUMIFS(…), SUMIFS(…))

Or

SUMIFS(…) + SUMIFS(…) + SUMIFS(…)

For example, to sum Grapes sales (H1) in the North region (H2), the formula is:

=SUMIFS(C2:C10, A2:A10, H1, B2:B10, H2) + SUMIFS(D2:D10, A2:A10, H1, B2:B10, H2) + SUMIFS(E2:E10, A2:A10, H1, B2:B10, H2)
SUMIFS formula for multiple columns

Array formula to conditionally sum multiple columns

The SUM formula for multiple criteria is very much like that for a single criterion - you just include additional criteria_range=criteria pair(s):

SUM((sum_range) * (--(criteria_range1=criteria1)) * (--(criteria_range2=criteria2)))

For instance, to sum sales for the item in H1 and the region in H2, the formula goes as follows:

=SUM((C2:E10) * (--(A2:A10=H1)) * (--(B2:B10=H2)))

In Excel 2019 and older, remember to press Ctrl + Shift + Enter to make it an CSE array formula. In dynamic array Excel 365 and 2021, a normal formula will work fine as shown in the screenshot:
Sum multiple columns with multiple criteria

SUMPRODUCT formula with multiple criteria

The easiest way to sum multiple columns based on multiple criteria is the SUMPRODUCT formula:

SUMPRODUCT((sum_range) * (criteria_range1=criteria1) * (criteria_range2=criteria2))

As you can see, it's very similar to the SUM formula, but does not require any extra manipulations with arrays.

To sum multiple columns with two criteria, the formula is:

=SUMPRODUCT((C2:E10) * (A2:A10=H1) * (B2:B10=H2))
SUMPRODUCT formula for multiple columns with two criteria

These are the 3 ways to sum multiple columns based on one or more conditions in Excel. I thank you for reading and hope to see you on our blog next week!

Practice workbook for download

Sum if multiple columns - examples (.xlsx file)

91 comments

  1. =(SUMIFS('STK Sheet'!H16:H400,'STK Sheet'!E16:E400,"#4 ACSR",'STK Sheet'!C16:C400,"N"))*(SUMIFS('STK Sheet'!D16:D400,'STK Sheet'!E16:E400,"#4 ACSR",'STK Sheet'!C16:C400,"N"))

    I have this formula which multiplies the linear footage of wire(column H) as long as column E shows a specific wire sizer and column C shows N for new wire. I have now created a column D that shows if there are 1, 2, or 3 wires at the location. the above formula does not work because it is taking the sum of the first statement and multiplying it by the sum of the 2nd. I need it to multiply each linear footage(H) by each number of wire(D) then sum all of that together.
    H1*D1 + H3*D3 + H7*D7 etc.
    any helpful tips?

      • I tried this previously and still was unable to make it work the way I needed it to. If column E and C are true I need H and D to be multiplied and added respectively. Maybe I just was not writing my sumproduct correctly

        • I believe I figured it out.
          =SUMPRODUCT(--('STK Sheet'!E16:E400="#4 ACSR"),--('STK Sheet'!C16:C400="N"),('STK Sheet'!H16:H400),('STK Sheet'!D16:D400))
          As I am sure you know the "--" makes those columns into numerical values so that it serves the same purpose as the SUMIF criteria

  2. may I ask how to add numbers from different column with #n/a (error) and text in cells and also hidden.
    example: How to add this numbers from A1 to H1 ignoring error and text and also hidden column or to add the numbers selected cells ignoring error and text. like A1+B1+E1+F1+H1=300 or A1:H1=300 but errors and text or hidden column are being ignored and the formula can be applied to the rest of the rows by dragging down or copying. thank you so much for your response to this.
    A1 B1 E1 F1 H1

    1. #N/A WAIVED 100 WAIVED 200
    2. 500 WAIVED 120 #N/A 50

  3. Using your example, I want the sum for Apples but only for January and March but then also removing the February.

    Is that possible using sumproduct, please?

    • Please, anyone?

      • Hi!
        Use data for January and March only

        =SUMPRODUCT((C2:C10) * (A2:A10=H1) * (B2:B10=H2)) + SUMPRODUCT((E2:E10) * (A2:A10=H1) * (B2:B10=H2))

        • Thank you so very much!

          • This can also be done with sumifs, right? Just trying to understand if the results would be indifferent in case we use sumifs for summing non -adjacent columns with single or multiple criteria

        • Hi is there a way to make this exact formula dynamic though? for example if i have 12 months of data, i only want to sum up the month columns for apple, if the date range is less than or equal to june. and then for grapes i might wnt to see date range is less than or equal to august. and so forth for other fruits. i want to be able to drop the formula without having to manually indicate with columns to sum up to.

          • Hi! For the last example in the article above, you can add the month selection in cell H3. The column with the data of the desired month can be received with the INDEX function.

            =SUMPRODUCT((INDEX(C2:E10,,MATCH($H$3,$C$1:$E$1,0))) * (A2:A10=H1) * (B2:B10=H2))

  4. Great work done by you! thanks alot for the details topics covered very briefly. Keep it up and shared the valuable knowledge with community.

  5. Greetings,

    Is there a way to use SUMIF, SUMIFS or SUM(IF) searching the criteria in an array?

    For example:

    =SUMIF(B1:B10,A1:A4,C1:C10)

    A B C D E F
    1 ABC ABC 10
    2 ABC BCD 25
    3 XYZ CDE 30
    4 DEF DEF 10
    5 RST 20
    6 DEF 10
    7 GHI 15
    8 TUV 20
    9 BCD 30
    10 CDE 10

    The result of the example would be = C1+C2+C4+C6+C9+C10

    My need for something like this is because in my spreadsheet my array of criteria have 70 values (for instance the 'B1:B4' in the above example is more like 'B1:B70'), and the sumrange have over 1000 lines.

    Thank you all in advance!

  6. Hi, I'd like to create a formula that multiplies data in pairs of cells if they're not blank:

    The idea is for a cost sheet where there are 6 columns.
    The choice is either hours and hourly cost OR number of days and daily rate OR an overall value which would just be multiplied by 1 for the total, then the total column at the end.
    I've tried sum/sum if (honestly been working my way around the self-help guides) but I'm clueless and at best I am only able to add 2 columns together whereas I want them multiplied for a total cost.

    Hours, Hourly Rate, Days, Daily Rate, Estimated Value, Total
    5, 5, blank, blank, blank, total = 5x5
    OR
    Blank, blank, 10, 10, blank, total =10x10
    OR
    Blank, blank, blank, blank, 500, total = 500x1 (or just to copy the value entered in the estimated value cell)

    Hope this is clear - it's the best I can explain without being able to add a screenshot or excel sheet.

    Thanks in advance for any help! :)

  7. Is there a chance to sum up the elements in column C in excel if the coordinates in columns A and B are repeated (at least once but maybe more)? So I mean a situation when it will be like this

    A B C
    0 1 4
    0 1 2
    0 1 3
    0 2 3
    ....

  8. =IF(COUNTIF(I5, "*mlg*"),H5/100000)COUNTIF(I5, "*grm*"),H5/1000))

    I am new in excel. Please solved this issue. What is right formula.

  9. Greeting to Ablebits team☺,

    I am thankful to you all for such amazing & detailed explanation on excel topics and "also for providing the excel sheet".

    But, In some of my previously read articles there are no excel sheets provided for practice.

    I would request the team to provide excel example sheet for all the articles. If possible, then please add excel example sheets of previous articles also.

    Feedback: -
    1) Kindly add Excel practice sheet for each article.
    2) Arrange all related topics sequentially.

  10. Hi,

    Anyone can help me what formula to use, basically I want to get the sum if date falls under Oct/22, Nov/22, Dec/22 and so on.
    Appreciate your help. Thanks!

    SKU 10/22/2022 10/29/2022 11/5/2022 11/12/2022 11/19/2022 11/26/2022 12/3/2022 12/10/2022 12/17/2022 12/24/2022 12/31/2022 1/7/2023 1/14/2023 1/21/2023 1/28/2023 2/4/2023 2/11/2023 2/18/2023 2/25/2023 3/4/2023 3/11/2023 3/18/2023
    40015048001 0 0 0 0 0 0 100000 0 0 0 200000 0 0 0 0 200000 0
    40015048002 0 0 50000 50000 50000 0 0 20000 20000 20000 50000 50000 50000 0 0 0 50000
    40015048003 47300 40000 120000 60000 15000 0 0 0 0 0 19084 19084 19084 59358 59358 59358 59358
    40015048004 78720 0 0 0 0 0 0 1324 0 0 19084 19084 19084 59358 59358 59358 59358

  11. The formula =SUM((C2:E10)*(--(A2:A10=H1))) doesn't work with me neither by pressing ENTER or CTRL+SHIFT+ENTER.

  12. Hi
    How can I sum something like this:

    WA11
    100
    250

    WA9
    3000

    WA11
    25
    333

    Just sum of all WA11, and they are all in same column?

    Thanks

  13. Feel a bit greedy to give away my personal findings, but "the time has come". Cool kids don't use SUMIF (no offence) while there is more elegant and practical way to aggregate data with the arrays. You described the idea very well, my comment is just for the execution. SUM(IF(A2:A10=H1, C2:E10)) and ctrl + shft+enter gives the same result but in a more intuitive way. And this logic is applicable to any aggregate function such as avg, median or count. Moreover, number of conditions has no limits as well. Lets say we want apples for Jan and Feb: SUM(IF(A2:A10=H1,IF(C1:E1 "Mar", C2:E10))) ctrl + shft+enter. This logic can be also implemented inside index - match, but that's another story...

  14. Using the table above, how would I create the formula to find the total sales of Apples in the East during March, without creating values in the H column?

    Thank you so much!
    James

  15. I learned new thing to solve my problem today.
    I am trying to sum values in an array if the condition is met. This array width is ever changing based on criteria.
    I leave the setting of array width to later part as I did not succeed at the fixed width array too.

    My data is set as Table in excel instead of range so that all formula grow together with the table when user add new data.
    Here is my formula:
    =SUMPRODUCT((RegByModel[[#All],[Jan-15]:[Mar-15]])*(--(RegByModel[[#All],[Model Name]]=Calculation!G81)))

    It should sum all values in Table "RegByModel", column [Jan-15] to [Mar-15],
    if the criteria in Table "RegByModel", column [Model Name] equals to "Calculation!G81" which is a text value.

    If I break the formula into 2 parts, it works fine. But when I combine them into SUMPRODUCT formula, it gave #VALUE! error.
    I tried using SUM formula too, same condition.

    I use the function "Evaluate Formula" to check, it returns that the first part of the formula is causing error.
    The first part of the formula is (RegByModel[[#All],[Jan-15]:[Mar-15]])

    If anyone might have an idea on how to solve this, appreciate your input.
    Thanks!

      • Thanks for your quick reply Alexander!
        Can I try to understand more which size is not same? Cell height or Width?

        If I compare to the example =SUMPRODUCT((C2:E10) * (A2:A10=H1))

        (C2:E10) = RegByModel[[#All],[Jan-15]:[Mar-15]] >> There is 3 columns in the example, and 3 columns in my formula. Each column denotes a month.
        A2:A10 = RegByModel[[#All],[Model Name]] >> Single column for example and my formula.
        H1 = Calculation!G81

        Hope to get your further reply. Thanks.

          • Thanks Alexander for your kind help.
            Think I need to break this intention into 2 steps.

  16. This is very insightful. Pivot tables can also be used to get the required values. Though we have to update it if anything changes in the data set....Nice analysis, especially with the sumproduct and sum functions.

  17. Please can the SUMIF with conditions return a blank cell?

    • Hi!
      The SUMIF function returns a number. If nothing is found, it returns 0. You can replace zero with an empty value using the IF function.
      For example,

      =IF(SUMIF(B2:B10, F1, C2:C10) > 0,SUMIF(B2:B10, F1, C2:C10),"")

  18. The writer of this article is the Hero we didn't know we needed.... Until we needed it.

    I had a hell of a time Getting the Proper SUMIFS format after i needed to add a second Sum range.

    Worked like a champ

    =SUMIFS('Monthly Expenses'!D4:D27,'Monthly Expenses'!C4:C27,Values!E1) +SUMIFS('Monthly Savings'!C4:C10,'Monthly Savings'!B4:B10,Values!E1)

    Thanks

  19. Thank you, this article is my lifesaver. I spent hours and days trying a find a solution before stumbling upon this. :)

  20. Very nice; very elegant. Thank you!
    It's been years since I used Excel, and then only as an amateur.

    Just wanted to point out that a possibly-hidden row (above or below) could have cells that each contain a simple SUMIF for their particular column. The grand total would simply sum horizontally across those cells.

    I used something like this when I wanted cyclic period information that would expire after 'n' periods. Insert a new column between the titles and the previous period data, and you're off and running.

    I've bookmarked this blog for future reference.

Post a comment



Thank you for your comment!
When posting a question, please be very clear and concise. This will help us provide a quick and relevant solution to
your query. We cannot guarantee that we will answer every question, but we'll do our best :)