+ Reply to Thread
Results 1 to 6 of 6

Sumproduct needs optimization

  1. #1
    Registered User
    Join Date
    06-27-2018
    Location
    uSA
    MS-Off Ver
    2013
    Posts
    2

    Sumproduct needs optimization

    Hi,
    I am using SUMPRODUCT to summarize the vacation days for all employees for each month. My formula looks like this:
    =SUMPRODUCT(
    ('Cal'!$B$4:$B$160=Summary!$B8)*
    (('Cal'!$C$4:$ND$160="VC")+
    ('Cal'!$C$4:$ND$160="SK")+
    ('Cal'!$C$4:$ND$160="TR")+
    (('Cal'!$C$4:$ND$160="HVC")/2)+
    (('Cal'!$C$4:$ND$160="HSK")/2)+
    (('Cal'!$C$4:$ND$160="HTR")/2))*
    ('Cal'!$D$3:$ND$3>=$E$4)*
    ('Cal'!$D$3:$ND$3<=$F$4))

    The vacation days are entered by the employees in sheet Cal and the formula is in sheet Summary. Both sheets are part of the same workbook.

    This formula runs for number of employees * months in the year and has slowed down my excel sheet considerably.
    Can you please suggest how can I optimize it?
    P.S. I cannot use SUMIFS as the values I am counting - VC, SK, etc. are non-numeric
    Last edited by nehabansal82; 06-27-2018 at 03:29 PM.

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

    Re: Sumproduct needs optimization

    The non numeric values are not stopping you from using sumifs (although countifs would be the appropriate choice), but the division by 2 where records are equal to HVC,HSK or HTR do stop you from using it with a little offset trickery.

    Are D3:ND3 days of the year in ascending order?

    If so then setting up a dynamic named range could help.

    Create a named range that refers to

    =INDEX(Cal!$D$4:$ND$160,MATCH($E$4,Cal!$D$3:$ND$3)):INDEX(Cal!$D$4:$ND$160,MATCH($F$4,Cal!$D$3:$ND$3))

    Note that the 2 ranges highlighted in red will need to be qualified with the relevant sheet name from your workbook.

    Once this is none, edit your existing formula to replace each occurrence of the range 'Cal'!$D$4:$ND$160 with the new name.

    Doing this will mean that the formula is not caluclauting 335 unnecessary columns of data if the dates in E4 and F4 only span 30 days.

    If you have empty rows at the bottom you could further improve this by making the last row dynamic as well.

    Edit:-

    Was having a bit of trouble getting my thoughts on order on this one, see if this produces the correct results, it's volatile so will potentially need to recalculate more often than sumproduct, but if it works it might be worth a try.

    =SUM(COUNTIFS(Cal!$A$4:$A$160,Summary!$A1,OFFSET(Cal!$D$4:$D$160,0,COLUMN($D$4:$ND$4)-COLUMN($D$4)),{"VC","SK","TR","JD","BR","LOA"}),
    COUNTIFS(Cal!$A$4:$A$160,Summary!$A1,OFFSET(Cal!$D$4:$D$160,0,COLUMN($D$4:$ND$4)-COLUMN($D$4)),{"HVC","HSK","HTR"})/2)
    Last edited by jason.b75; 06-27-2018 at 03:58 PM.

  3. #3
    Registered User
    Join Date
    06-27-2018
    Location
    uSA
    MS-Off Ver
    2013
    Posts
    2

    Re: Sumproduct needs optimization

    Thanks Jason. I tried the formula however it always returns 0.

  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,498

    Re: Sumproduct needs optimization

    This could work, I've used the sumproduct in a similar way but would have to test it...

    =SUMPRODUCT(('Cal'!$B$4:$B$160=Summary!$B8)*(('Cal'!$C$4:$ND$160={"VC","SK","TR"})*(('Cal'!$C$4:$ND$160={"HVC","HSK",”HTR"})/2))*('Cal'!$D$3:$ND$3>=$E$4)*('Cal'!$D$3:$ND$3<=$F$4))

    edited, adjusted to add parens and multiplier - unable to test
    Last edited by Sam Capricci; 06-27-2018 at 04:22 PM.
    Make contributors happy, click on the "* Add Reputation" as a way to say thank you.
    Sam Capricci

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

    Re: Sumproduct needs optimization

    Could you describe your sheet in a bit more detail.

    From what I can see, this is a holiday planner, Cal!A4:A160 contain employee id of some kind (no duplicates), D3:ND3 Jan 1 to Dec 31, D4:ND4 codes to identify absense type, with the last 3, HVC, HSK, HTR denoting 1/2 day.

    E4 and F4 contain the start and end dates for the month / period of interest.

    Summary!B8 contains the employee id of interest.

    Just noticed that you edited your original post, I didnt refresh it so 1 of the ranges was wrong in my formula.

    It should have been

    =SUM(COUNTIFS(Cal!$A$4:$A$160,Summary!$B8,OFFSET(Cal!$D$4:$D$160,0,COLUMN($D$4:$ND$4)-COLUMN($D$4)),{"VC","SK","TR","JD","BR","LOA"}),
    COUNTIFS(Cal!$A$4:$A$160,Summary!$B8,OFFSET(Cal!$D$4:$D$160,0,COLUMN($D$4:$ND$4)-COLUMN($D$4)),{"HVC","HSK","HTR"})/2)

    However, if my analysis of your sheet is correct then a much simpler approach could be used. Did I miss anything?

    Based on the above assumptions.

    =SUM(COUNTIFS(INDEX(Cal!$D$4:$ND$160,MATCH(Summary!$B8,Cal!$A$4:$A$160,0),0),{"VC","SK","TR","JD","BR","LOA"},Cal!$D$3:$ND$3,">="&$E$4,Cal!$D$3:$ND$3,"<="&$F$4),
    COUNTIFS(INDEX(Cal!$D$4:$ND$160,MATCH(Summary!$B8,Cal!$A$4:$A$160,0),0),{"HVC","HSK","HTR"},Cal!$D$3:$ND$3,">="&$E$4,Cal!$D$3:$ND$3,"<="&$F$4)/2)

    Both formulas are untested.
    Last edited by jason.b75; 06-27-2018 at 04:31 PM.

  6. #6
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Sumproduct needs optimization

    Cross-posted at: https://www.mrexcel.com/forum/excel-...st5095516.html
    Please read Excel Forum's Cross-Posting policy in rule 8: http://www.excelforum.com/forum-rule...rum-rules.html
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

+ 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. [SOLVED] Slow time deleting filtered rows. Optimization help (sumproduct).
    By Pojzon in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 02-20-2018, 07:41 AM
  2. Sumproduct change for optimization. Sumif perhaps?
    By Pojzon in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 11-25-2017, 09:29 AM
  3. [SOLVED] SUMPRODUCT formula optimization for multiple criteria addition
    By Strazdas in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-08-2015, 03:01 AM
  4. [SOLVED] sumproduct optimization
    By miller_ilya in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-18-2013, 09:23 AM
  5. Sumproduct formula optimization
    By sinspawn56 in forum Excel General
    Replies: 4
    Last Post: 11-06-2012, 02:23 PM
  6. I need of optimization -Please help!
    By Mm73 in forum Excel General
    Replies: 1
    Last Post: 08-25-2008, 02:18 PM
  7. optimization
    By kckar in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-09-2005, 01:05 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