+ Reply to Thread
Results 1 to 8 of 8

Sumproduct over dynamic range

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-10-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    272

    Sumproduct over dynamic range

    Hello Excel guru's,

    Can the following formula be adapted to run over a dynamic range. Currently it will only work if the range is fixed to those rows containing data, just the first 21 rows.

    =SUMPRODUCT(--('QO'!$J$12:J500="SQ"),--('QO'!$F$12:F500),--(MONTH('QO'!$E$12:E500)=MONTH(TODAY())))
    I'm using Sumproduct because it will be pulling data from a closed workbook.

    Thank you
    Last edited by sipa; 01-29-2019 at 07:17 AM.

  2. #2
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,706

    Re: Sumproduct over dynamic range

    So, you may find below variant will work as-is, pending data type in F (assumed to be numbers where numeric value)
    Formula: copy to clipboard

    =SUMPRODUCT((('QO'!$J$12:J500="SQ")*(TEXT('QO'!$E$12:E500,"yyyymm")=TEXT(TODAY(),"yyyymm"))),'QO'!$F$12:F500)


    that being said, it is always a good idea when using SUMPRODUCT to limit your range as much as possible, even more so when used in conjunction with Volatile functions [like TODAY() ]

    If we assume Column J is always Text then I would suggest you create a Dynamic Named Range a) to avoid repetition in your calc, and b) succinctness... so, via Name Manager create following:

    Formula: copy to clipboard
    Name: =_Data
    RefersTo: ='QO'!$A$12:INDEX('QO'!$J:$J,MAX(12,MATCH(REPT("Z",255),'QO'!$J:$J)))


    then, modify SUMPRODUCT to:

    Formula: copy to clipboard
    =SUMPRODUCT(((INDEX(_Data,0,10)="SQ")*(TEXT(INDEX(_Data,0,5),"yyyymm")=TEXT(TODAY(),"yyyymm"))),INDEX(_Data,0,6))


    the _Data range will expand / contract relative to last text entry found in Column J on 'QO' sheet

  3. #3
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,706

    Re: Sumproduct over dynamic range

    edit: on an aside, assuming your dates are stored as dates (where populated) you could use SUMIFS rather than SUMPRODUCT, this will be much more efficient.

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

    Re: Sumproduct over dynamic range

    Quote Originally Posted by XLent View Post
    assuming your dates are stored as dates (where populated)
    If they were not actual dates then the MONTH function would not work in the existing formula.

    =SUMIFS('QO'!$F$12:F500,'QO'!$J$12:J500,"SQ",'QO'!$E$12:E500,">"&EOMONTH(TODAY(),-1),'QO'!$E$12:E500,"<="&EOMONTH(TODAY(),0))

  5. #5
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,706

    Re: Sumproduct over dynamic range

    Quote Originally Posted by jason.b75 View Post
    If they were not actual dates then the MONTH function would not work in the existing formula.
    No, that's not correct. MONTH will explicitly coerce so if they're strings, rather than numbers, it will coerce and if valid date "strings" it will work.

    The fact OP was stating they were getting an error implied, to me, that there are either values in the "date" or "sum" ranges that cannot be explicitly coerced.

    The revised approach removes the explicit coercion from both elements -- TEXT will still work as expected for dates and/or dates stored as strings and will ignore other values (effectively).

    A1: apple
    A2: '29-Jan {i.e string}
    A3: 29/1/2019

    MONTH will generate errors on A1 and work for A2 & A3 whereas TEXT will work for all (i.e. FALSE for A1, TRUE for A2 & A3).

    edit: I should have used a null string in my example as if formulae involved in the date/sum precedent ranges they will be responsible for the coercion errors (c/o --, MONTH, EOMONTH etc)
    Last edited by XLent; 01-29-2019 at 08:19 AM.

  6. #6
    Forum Contributor
    Join Date
    06-10-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    272

    Re: Sumproduct over dynamic range

    Hi Jason,
    Thanks for replying. The dates are actual dates.
    Unfortunately Sumifs won't work on closed workbooks.

  7. #7
    Forum Contributor
    Join Date
    06-10-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    272

    Re: Sumproduct over dynamic range

    XLent,

    Thanks for you reply.
    Your formula revision is now working for me as expected, thank you for that.
    HTML Code: 
    I will also try and follow your advice and implement a Dynamic Named Range, I can see how that would be more efficient. I'll come back if I encounter any problems.
    With thanks and regards

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

    Re: Sumproduct over dynamic range

    Corrected twice in one thread on things that I could have sworn I was right.

    This is me keeping quiet now

+ 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. Dynamic range from which to use =SUMPRODUCT()
    By Dralky in forum Excel General
    Replies: 10
    Last Post: 06-30-2018, 12:59 AM
  2. Replies: 2
    Last Post: 01-20-2017, 04:27 PM
  3. Sumproduct of Dynamic Range
    By deepak2jadav in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 06-28-2014, 09:01 AM
  4. [SOLVED] Sumproduct with a dynamic range...is that the only way?
    By som3on3_10 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-30-2014, 02:35 AM
  5. Sumproduct for dynamic range
    By Bob@Sun in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-05-2010, 06:32 AM
  6. Sumproduct, dynamic range
    By jmicdk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-18-2008, 08:43 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