+ Reply to Thread
Results 1 to 9 of 9

Variable sumif?

  1. #1
    Forum Contributor
    Join Date
    12-02-2008
    Location
    Brisbane
    MS-Off Ver
    2016
    Posts
    811

    Variable sumif?

    How can I =sumif when I have variable criteria? Or should I be using =sumproduct? The attached sample file explains it better.

    Thanks for all ideas.
    Attached Files Attached Files
    Last edited by BRISBANEBOB; 08-16-2010 at 05:46 PM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Variable sumif?

    SUMIF will suffice - use INDEX (with MATCH) to establish the variable sum_range

    =SUMIF($B$3:$B$11,$B$16,INDEX($C$3:$N$11,0,MATCH($B17,$C$2:$N$2,0)))

  3. #3
    Forum Contributor
    Join Date
    12-02-2008
    Location
    Brisbane
    MS-Off Ver
    2016
    Posts
    811

    Re: Variable sumif?

    Please can you explain what function the '0' plays in the Index formula?

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Variable sumif?

    all rows - see XL help for more info.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,352

    Re: Variable sumif?

    Try:

    Please Login or Register  to view this content.

    Regards

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Variable sumif?

    @TMShucks - the below:

    Please Login or Register  to view this content.
    is Volatile given use of OFFSET but also [interestingly?] (XL2002+) by the fact that the optional sum_range is smaller than the non-optional range
    (see: http://www.decisionmodels.com/calcsecretsi.htm - this behaviour was actually discovered on this board).

    The INDEX alternative is semi-volatile only - will calculate upon workbook open but thereafter only on those occasions where a direct precedent is altered.
    Last edited by DonkeyOte; 08-16-2010 at 06:06 PM. Reason: typo

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,352

    Re: Variable sumif?

    @DonkeyOte.

    Thanks for the guidance. Are you saying that the formula *will* work but should not be used ... or rather, that the alternative you provided is a better option?

    If it works, is the impact on calculation, etc., significant. Is it acceptable if used sparingly?

    Thanks ... sorry to be pedantic but I'd like to understand a little more.

    Regards

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Variable sumif?

    I personally prefer non-volatile alternatives but OFFSET is very fast so on a one-off basis OFFSET is probably quicker.

    However, goes without saying that the impact Volatility will have on a model depends on the specifics - ie number of Volatiles and number of Volatile actions being performed (we assume Auto Calc.)

    Regards that specific construct - I would say it's generally accepted practice that you should endeavour to make the dimensions of both ranges consistent.

    =SUMIF(B3:B11,B16,OFFSET(B3:B11,0,MATCH(B17,C2:N2,0)))

    would be preferable

    Point being that if we disregard OFFSET (ie remove that Volatile element) and have a construct say of:

    =SUMIF(B3:B11,B16,C3)

    the above is open to error prior to XL2002 and is Volatile thereafter (the sum_range is implicit as far as XL is concerned)

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,352

    Re: Variable sumif?

    @DonkeyOte

    Thank you for the clarification ... and for spending the time to explain so fully.

    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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