+ Reply to Thread
Results 1 to 9 of 9

Using SUMIFS with multiple OR criteria

  1. #1
    Registered User
    Join Date
    10-22-2014
    Location
    Washington, DC
    MS-Off Ver
    2010
    Posts
    4

    Using SUMIFS with multiple OR criteria

    First time posting here - stuck on a problem!

    I want to SUM a numerical column if the corresponding text column contains one of several strings of text.

    By way of example, if the word "hotdog" appears in column E, I want to sum the corresponding numbers in column D

    This works well enough if I use: =SUMIF(E:E, "*hotdog*",D:D)

    Where I am getting stuck is if I try to sum cells with multiple alternative words. For example, if the strings "hotdog" OR "burger" appear in column E, I want the sum of column D.

    All of the solutions I have found on the Internet so far ignore one twist: If a cell contains BOTH "hotdog" AND "hamburger" then I only want to account for the number in column D once. For this reason, the following formula is not working: =SUM(SUMIFS(D:D,E:E,{"*hotdog*","*burger*"})) That formula seems to work up until it finds a cell containing both strings, and then it doubles the column D output.

    Who has ever addressed this before? Thanks!

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,733

    Re: Using SUMIFS with multiple OR criteria

    Well, why not subtract from your formula the numbers when both hotdog and burger appear together in column E, i.e.:

    =your_formula -SUMIFS(D:D,E:E,"*hotdog*",E:E,"*burger*")

    as you will have double-counted the values from column D when both occur.

    Hope this helps.

    Pete

  3. #3
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Using SUMIFS with multiple OR criteria

    One way would be to sum column D and then subtract the column D values where neither word appears, i.e.

    =SUM(D:D)-SUMIFS(D:D,E:E,"<>*burger*",E:E,"<>*hotdog*")
    Audere est facere

  4. #4
    Registered User
    Join Date
    10-22-2014
    Location
    Washington, DC
    MS-Off Ver
    2010
    Posts
    4

    Re: Using SUMIFS with multiple OR criteria

    Oh, excellent! I think that will work when I only have two criteria (hotdog & burger).

    If I have more than that, any suggestions? For example, if I want to return the sum of column D if column E contains the strings "hotdog" OR "burger" OR "popcorn" OR "chips"

    Regardless of the number of those keywords that appear in the cell, I only want to count column D once. Unfortunately, I don't think your great solution will work in that situation. Got another work-around?

  5. #5
    Registered User
    Join Date
    10-22-2014
    Location
    Washington, DC
    MS-Off Ver
    2010
    Posts
    4

    Re: Using SUMIFS with multiple OR criteria

    Another great suggestion, daddylonglegs! I will test it out now!

  6. #6
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,733

    Re: Using SUMIFS with multiple OR criteria

    If you have 3 words, then you will have triple-counted the values in column D when all 3 occur together, so you will need to subtract two times the sum from all three criteria. However, you will have double-counted when word1 and word2 occur together, when word2 and word3 occur together, and when word1 and word3 occur together, so you will need to subtract these sums (once).

    For 4 conditions, you will have quadruple-counted when all 4 occur together, so subtract three times the sum. Also, subtract two times the sum of any 3 words together, and single-subtract any 2 words together - it gets a bit messy ...

    Hope this helps.

    Pete

  7. #7
    Registered User
    Join Date
    10-22-2014
    Location
    Washington, DC
    MS-Off Ver
    2010
    Posts
    4

    Re: Using SUMIFS with multiple OR criteria

    Thank you both for your help. Daddylonglegs' suggestion ultimately won the day. Pete - your suggestion would have worked but, you're right, it would have gotten messy!

    I wish there was a more straightforward SUMIFS with OR function. Tons of people seem to struggle with it, and I am just now learning about arrays.

    Thanks again!

  8. #8
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,733

    Re: Using SUMIFS with multiple OR criteria

    Ah well, I'm glad you got a solution which worked for you.

    Pete

  9. #9
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Using SUMIFS with multiple OR criteria

    Another way to get the result you want is to use this formula

    =SUMPRODUCT((MMULT(ISNUMBER(SEARCH({"hotdog","burger"},E2:E100))+0,{1;1})>0)+0,D2:D100)

    (better with a restricted range as shown). In that version you can replace the "array constant" {"hotdog","burger"} with one containing any number of search terms.......but you also need to change {1;1} part to contain as many 1s as you have search strings, e.g. for {"hotdog","burger","popcorn"} you need {1;1;1}

+ 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] Sumifs multiple criteria
    By Hudson in forum Excel General
    Replies: 3
    Last Post: 03-18-2013, 02:55 PM
  2. Replies: 2
    Last Post: 01-23-2013, 06:25 AM
  3. Replies: 3
    Last Post: 11-21-2012, 04:57 PM
  4. Need help with SUMIFS, Multiple criteria
    By heatherromo in forum Excel General
    Replies: 4
    Last Post: 05-02-2012, 02:54 PM
  5. 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