+ Reply to Thread
Results 1 to 17 of 17

sum a RANGE from one criteria

  1. #1
    Forum Contributor
    Join Date
    08-23-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    139

    sum a RANGE from one criteria

    Hello,

    I have been working with lots of sumif() this morning and feel that I might have got my mind stuck in that method. My sumif()'s are working fine but now i have come to another type of sum that i'd like to do and I am stuck.

    Problem:
    I would like to check A:A for a given criteria, but the result should be a sum of H:K. Sumif, and sumifs look for a single, or multiple criteria but they don't appear to be able to sum the range (h:k).

    Is there a formula that can do this, without it being an array (my sheet will get very large and arrays will considerably slow down performance). I seem to vaguely remember a sumproduct() can do it somehow but as i said i have got my head stuck in sumif mode and can't think of it!

    A non-working example is:
    Please Login or Register  to view this content.
    thanks in advance.
    IF("helping me", "thanks", "need more detail?")

  2. #2
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: sum a RANGE from one criteria

    Try this

    =sumif(A2,Transactions!$A$2:$A$23000,Transactions!$h$2:$h$23000) + sumif(A2,Transactions!$A$2:$A$23000,Transactions!$k$2:$k$23000)
    Cheers!
    Deep Dave

  3. #3
    Forum Contributor
    Join Date
    08-23-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: sum a RANGE from one criteria

    Hello,

    Thanks for the prompt reply.

    That would work, but in fact the columns that i need to show the sum of are H,I,J,K and this would result in a very long formula. Since the formula is to be repeated in 100 rows i fear that this will affect the speed of the sheet.

  4. #4
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: sum a RANGE from one criteria

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window (or use the paperclip icon).

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

    Re: sum a RANGE from one criteria

    Try

    =sumif(Transactions!$A$2:$A$23000,A2,OFFSET(Transactions!$h$2:$k$23000,0,{0,1,2,3}))

  6. #6
    Forum Contributor
    Join Date
    08-23-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: sum a RANGE from one criteria

    Please Login or Register  to view this content.
    Well rather than posted a sample workbook I will show you what the formula would look like if i just used sumif().

    Is there a way to contract this?

    Rough description: The formula first looks at the total stock booked into my shop, subtracting the total number of sales. Then, in () brackets it tells me the total stock available in various storage locations - amounts which are recorded in columns H,I,J,K.

  7. #7
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: sum a RANGE from one criteria

    I cannot help out unless I see how the data is placed..

    Please try and attach a sample.

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

    Re: sum a RANGE from one criteria

    Quote Originally Posted by NeedForExcel View Post
    I cannot help out unless I see how the data is placed..

    Please try and attach a sample.
    Or just see post #5.

    There is adequate information in post #1, no need for a sample file.

  9. #9
    Forum Contributor
    Join Date
    08-23-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: sum a RANGE from one criteria

    Jason.b75 i didn't see your post.

    Thank you, i will try it now

  10. #10
    Forum Contributor
    Join Date
    08-23-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: sum a RANGE from one criteria

    Ok, I have tried the formula in post #5 and it only shows the value in colH. It does not sum up the values in col H:K

    As i mentioned, i think there is a way to use sumproduct. Something like...

    Please Login or Register  to view this content.
    this doesn't work though, but i might be using the formula in a way that is clouded by my use of sumif all morning :P

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

    Re: sum a RANGE from one criteria

    I have a habit of sneaking into a thread undetected

    I just noticed a typo in my formula, it should be


    =sumif(Transactions!$A$2:$A$23000,A2,OFFSET(Transactions!$h$2:$h$23000,0,{0,1,2,3}))

    If you wanted to try sumproduct it would be

    =sumproduct((Transactions!$A$2:$A$23000=A2)*Transactions!$h$2:$k$23000)

    There are pros and cons to both versions, the use of OFFSET makes the first formula volatile, while sumproduct is simply an array formula that doesn't need shift ctrl enter.

    See http://www.decisionmodels.com/calcsecretsi.htm for information on volatile functions and why they can be bad.

  12. #12
    Forum Contributor
    Join Date
    08-23-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: sum a RANGE from one criteria

    Jason you have been unbelievably helpful here!

    That formula works, but you have also shown me some information on how to make my sheets work faster in the future AND you have shown me a new way to use the offset function!

    I take it that {0,1,2,3} is asking the formula to loop a few times? This is going to be immensely useful to me as i currently have to use some very long formulas where this one would do it quicker.

    Huge thanks.

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

    Re: sum a RANGE from one criteria

    For what it's worth, the method that needforexcel suggested would be no less efficient, shorter formulas are often preferred for ease of editing, but both versions will take the same amount of processing.

    {0,1,2,3} defines the column position for offset based on the starting range of H2:H23000.

    0 refers to the same column, then 1,2 and 3 are the columns to the right, so 3 refers to K2:K23000 (3 columns right of the starting range).

    Effectively the formula says perform the sumif calculation on each of the 4 columns, then add them all together, so the same as needforexcel suggested, but with less typing.

  14. #14
    Forum Contributor
    Join Date
    08-23-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: sum a RANGE from one criteria

    A contraction of the formula i had, or another method that is shorter is what i was looking for.

    I was under the impression that a longer formula would take more processing power but i'm glad to see i was wrong about that.

    Unfortunately, both of your formulas don't work. The offset one is still only summing colH values and the sumproduct is giving a #N/A. I'm in the process of combing my data to make sure it is in the correct formatting at the moment.

  15. #15
    Forum Contributor
    Join Date
    08-23-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: sum a RANGE from one criteria

    To get around it, I am going to create an =sum(h2:k2) and drag it down to row 23000 on the transactions sheet, then do a single sumif() to get that columns figure in the worksheet i'm using.

    It's not clever, but i works :S

  16. #16
    Forum Contributor
    Join Date
    08-23-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: sum a RANGE from one criteria

    To get around it, I am going to create an =sum(h2:k2) and drag it down to row 23000 on the transactions sheet, then do a single sumif() to get that columns figure in the worksheet i'm using.

    It's not clever, but i works :S

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

    Re: sum a RANGE from one criteria

    Anything non numeric (text, errors, of formulas that return blanks) in the sum range, H2:K23000 will cause the sumproduct to fail.

    Not sure why the offset version is failing though, it works fine for me on a simple test sheet.

    Have you edited the formula in any way in order to match the layout of your real data?

    edit:-

    Have you tried evaluating the formula?

    Go to the formulas tab on the excel ribbon, then click 'Evaluate formula'

    On the popup box, click evaluate and the formula in the window will show errors (1 for each column),click evaluate again and it should show the totals for the individual columns as an array, SUM({h,i,j,k})

    If any of these don't match up as expected then I would guess that you have some data formatted in a way that the formula is not recognising correctly.
    Last edited by jason.b75; 04-26-2016 at 08:53 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. Countifs with multiple criteria in single criteria range
    By MCP313 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 12-01-2016, 03:51 AM
  2. [SOLVED] COUNTIFS with multiple criteria in the same criteria range
    By Faridwahidi in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-23-2015, 01:04 PM
  3. [SOLVED] Macro for AverageIFS, with multiple criteria in the same criteria range
    By Faridwahidi in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 05-24-2014, 01:13 AM
  4. Replies: 1
    Last Post: 09-03-2013, 07:41 PM
  5. [SOLVED] Find a number closest to 30 in a range with one more criteria (criteria includes text)
    By Sarangsood in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-22-2013, 01:16 PM
  6. Replies: 3
    Last Post: 11-21-2012, 04:57 PM
  7. Replies: 1
    Last Post: 05-16-2011, 05:00 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