+ Reply to Thread
Results 1 to 15 of 15

Speeding up SUMPRODUCT/ SUMIFS array formula

  1. #1
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Speeding up SUMPRODUCT/ SUMIFS array formula

    Hi all,

    I have a large data set where I need to SUM cells IF a certain criteria is met without using helper columns. The formula I am currently using is giving the right results, though, as it is a SUMPRODUCT/ SUMIFS array formula it makes the file unnecessarily slow. I have already speeded it up by using:

    Please Login or Register  to view this content.
    at the beginning of the formula to not have it calculate the array if not relevant, this speeds it up by about a factor of 2 in my data set.

    Please Login or Register  to view this content.
    Now I was wondering if there is another "trick" to make it ignore calculations if not relevant. E.g. Only SUMIF data from the "IA" sheet if criteria is met and "skip" calculation of cells in the array that aren't relevant. Currently even if ALL data in the GREY cells is deleted, calculation times don't change!! The formula still seems to run through every single cell in the array and calculate the SUM of all PRODUCTS. Is it possible to rewrite the formula somehow so that it skips these cells? Or use a different approach/formula altogether?

    BTW I am currently testing the speed with a macro. Select the cells that need testing and press CONTROL+SHIFT+R. It gives me about 0.17 seconds for all "MIN IA" cells (29 cells in total). In my data set it's about 10 seconds as the array gets longer.
    Attached Files Attached Files

  2. #2
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2507
    Posts
    13,809

    Re: Speeding up SUMPRODUCT/ SUMIFS array formula

    SUMPRODUCT is having to calculate over one million rows unnecessarily. That is a major bottleneck.

    Try replacing the whole column references in the SUMIFS section to A7:ZZ409, A7:A409 ... etc.
    Dave

  3. #3
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: Speeding up SUMPRODUCT/ SUMIFS array formula

    I had tested that already, it makes NO difference or whatsoever! It seems to ignore the blank cells anyway, just like in any other SUMIF without SUMPRODUCT...

  4. #4
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2507
    Posts
    13,809

    Re: Speeding up SUMPRODUCT/ SUMIFS array formula

    Still not certain I get what you are wanting. I was addressing the speed issue.

    While I have not done a painstaking check of each step in the formula I did notice this part.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    It evaluates all "x"s in that range as 1 or TRUE. Is that your intent?

  5. #5
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: Speeding up SUMPRODUCT/ SUMIFS array formula

    Quote Originally Posted by FlameRetired View Post
    Still not certain I get what you are wanting. I was addressing the speed issue.
    I was referring to the speed as well! I tried A7:ZZ409 etc. in the SUMIFS part and get the same speed result.

    My intent is to SUM the data in the "IA" sheet for all cells on the "Range" sheet which contain either an "x", "xx", "xxx", " x", " x " etc., all numbers greater than zero, and ignore all cells where the attribute says "DROP" or "INACTIVE"

  6. #6
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2507
    Posts
    13,809

    Re: Speeding up SUMPRODUCT/ SUMIFS array formula

    all numbers greater than zero
    Try changing this part
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    to
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Doing so returns 14 in G4 at my end.

  7. #7
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: Speeding up SUMPRODUCT/ SUMIFS array formula

    Just tested it, it returns 14 indeed, but 14 is wrong! As I said, the results I am getting are correct with my original formula, it is just the speed that makes my file 10 seconds slower than it should...

  8. #8
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2507
    Posts
    13,809

    Re: Speeding up SUMPRODUCT/ SUMIFS array formula

    OK. I am having difficulty understanding the
    all numbers greater than zero
    part.

    I am not following the logic of that in the formula. Your formula is evaluating "x" as greater than 0. If your formula is returning correct values I am very confused since "x" is not a number ... but does return TRUE for being greater than zero. That is the nature of text to numbers comparisons. The inclusion of that test does not make sense to me if you want numbers > 0. Try selecting just the --(G$6:G$408 > 0) part of your formula in the formula bar and hit the F9 function key. You will see 1s corresponding with the "x"s.

    I need to step away from my computer for a few hours. I will return and look this later today.

  9. #9
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: Speeding up SUMPRODUCT/ SUMIFS array formula

    The first part of the formula:

    Please Login or Register  to view this content.
    just focuses on the numbers in the array and ignores the ones below zero
    Please Login or Register  to view this content.
    The second part:

    Please Login or Register  to view this content.
    is evaluating the "x"s, basically it checks the array for cells with "x", "xx", or "xxx"
    Please Login or Register  to view this content.
    and substitutes cells that contain blanks such as "x ", " x", " x "
    Please Login or Register  to view this content.
    otherwise it would neglect them which it shouldn't. So if the result is >0 (either number or x's) it counts these cells as TRUE. Don't get hung up to much with the ISNUMBER in the second part, that confused me too. For some reason it returns TRUE if the cell is not blank when you combine it with the these other formulas, maybe someone else can explain why... I'm sure there's a better way (less confusing) to write the formula.

    So in the end, both numbers (positive) and x's are counted (maximum three x's) in the formula, and it then SUMs the numbers from the "IA" sheets for these cells with the corresponding Attribute. It also ignores all items that are Dropped or Inactive

    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Speeding up SUMPRODUCT/ SUMIFS array formula

    Quote Originally Posted by FlameRetired View Post
    Try replacing the whole column references in the SUMIFS section to A7:ZZ409, A7:A409 ... etc.
    Quote Originally Posted by esbencito View Post
    I had tested that already, it makes NO difference or whatsoever!
    While I personally feel referencing only the data set is good practice, the IFS functions can actually efficiently handle the whole column/row references (cant find the documentation that states this, but MS has said it does).

    Lets also put into perspective what exactly is "slow" and define if its is reasonable according to the amount of work you are asking Excel to do. How long does calculation take for the whole workbook? How long do you think it should take?
    Ways to get help: Post clear questions, explain your overall goal, supply as much background as possible, respond to questions asked of you by those trying to help and post sample(s) files.

    "I am here to help, not do it for people" -Me

  11. #11
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Speeding up SUMPRODUCT/ SUMIFS array formula

    Couple general tips for speed:

    *755 named ranges, most of them resulting in ref errors...bad for speed. Clean up your named ranges.
    *Applying a style to every cell on a sheet, also bad for speed and file size. Likely to eventually lead to duplicate/excess styles. I am already seeing signs of corrupt styles in the file. As an example, the styles list on the home tab should not change in terms of the styles available regardless of where you are in the file...yours does. E1 and E2 for example list a different set of styles. Not a good sign.
    *Remove formulas that are not needed or result in errors. Column A on the Range sheet is all #REF (maybe due to the named range it uses being ref, which may point at an external file I dont have)

    I am still reviewing the formula...the INDEX in it using full column/row ranges is likely not good, ill post back soon

  12. #12
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Speeding up SUMPRODUCT/ SUMIFS array formula

    See if this formula is more efficient:

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


    I got the same results as your formula but simplified the considerations for x,xx,xxx,DROP and numeric. I also used the INDEX with a reference to just your data range.

    As the sample is small I didnt bother with speed testing it, as all results would be within margin of error on the timer. See how it compares in your actual data set.

  13. #13
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: Speeding up SUMPRODUCT/ SUMIFS array formula

    Quote Originally Posted by Zer0Cool View Post

    *755 named ranges, most of them resulting in ref errors...bad for speed. Clean up your named ranges.
    Since I had to reduce the file size, I obviously removed everything that wasn't relevant to the issue. Named ranges are clean and none of them result in #REF!

    *Applying a style to every cell on a sheet, also bad for speed and file size. Likely to eventually lead to duplicate/excess styles. I am already seeing signs of corrupt styles in the file. As an example, the styles list on the home tab should not change in terms of the styles available regardless of where you are in the file...yours does. E1 and E2 for example list a different set of styles. Not a good sign.
    Also not the case in my original file, but a good call out that I will keep in mind when developing spreadsheets in the future...

    *Remove formulas that are not needed or result in errors. Column A on the Range sheet is all #REF (maybe due to the named range it uses being ref, which may point at an external file I dont have)
    Again, not a #REF in my file and an essential formula, already removed as much as I could, that's why I am focusing on improving formulas now rather than deleting them...

    I am still reviewing the formula...the INDEX in it using full column/row ranges is likely not good, ill post back soon
    As you mentioned in your previous post, Excel's IFS functions can efficiently handle whole column/row references...

  14. #14
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: Speeding up SUMPRODUCT/ SUMIFS array formula

    Quote Originally Posted by Zer0Cool View Post
    See if this formula is more efficient:

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


    I got the same results as your formula but simplified the considerations for x,xx,xxx,DROP and numeric. I also used the INDEX with a reference to just your data range.

    As the sample is small I didnt bother with speed testing it, as all results would be within margin of error on the timer. See how it compares in your actual data set.
    Tested your formula and getting no difference in speed not even .001%. Excel seems to handle the whole columns very efficiently indeed.

  15. #15
    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
    53,053

    Re: Speeding up SUMPRODUCT/ SUMIFS array formula

    Please take a moment to read the forum rules and then amend your thread title to something descriptive of your problem - not what you think the answer might be. (think google search terms?). Once you have done this please send me a PM and I will remove this request. (Also, include a link to your thread - copy from the address bar)

    Many members search our previous posts, and thread titles play a big part of the search. I doubt anybody would do a search based on your title?

    To change a Title on your post, click EDIT POST then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    (note: this change is not optional )
    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

+ 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. SUMPRODUCT/SUMIFS Dynamic array doesn't works
    By regoroes in forum Excel General
    Replies: 5
    Last Post: 01-04-2018, 03:01 AM
  2. Trying to move SUMPRODUCT formula to SUMIFS
    By chimelle in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-20-2015, 05:08 PM
  3. [SOLVED] Convert SUMIFS formula to SUMPRODUCT
    By timbury1 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 11-08-2014, 01:18 PM
  4. Sumproduct with sumifs formula
    By nilani in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-22-2014, 08:50 AM
  5. Using Sumproduct or sumifs when a cell has a formula
    By cartica in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-15-2013, 04:02 PM
  6. [SOLVED] =SUMPRODUCT(SUMIFS....Formula Ammendment
    By 3smees23 in forum Excel General
    Replies: 2
    Last Post: 05-22-2012, 08:53 AM
  7. Speeding up Array
    By gti_jobert in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-13-2006, 10:45 AM

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