+ Reply to Thread
Results 1 to 14 of 14

SUMPRODUCT with several criteria

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

    SUMPRODUCT with several criteria

    Hi all,

    How can I rewrite below formula to only take into account the cells that contain a number that is greater than zero, as well as all cells that contain an "x" (such as "x", " x", "xx" or "xxx" etc.), but excluding cells that contain e.g. "LUX" which obviously has an "x" in it but rather forms a word...

    Please Login or Register  to view this content.
    current formula returns a #VALUE error.

  2. #2
    Forum Expert
    Join Date
    11-26-2013
    Location
    Colac, Victoria, Australia
    MS-Off Ver
    Excel 2016
    Posts
    1,309

    Re: SUMPRODUCT with several criteria

    If you want to count the number of times a character is repeated in a string:
    =LEN(A1)-LEN(SUBSTITUTE(A1,"x",""))
    This is better than the COUNT(SEARCH()) combination you used as it returns the number of times "x" appears in the string.

    Now, if you expand this to =IF(LEN(A1)-LEN(SUBSTITUTE(A1,"x",""))>=LEN(A1),1,0) you add a test to see if there are characters OTHER THAN X in the string. If so, as in the case of "LUX", it will return 0.

    Note, this will only work where there is x, xx, xxx etc. If there are spaces anywhere, the test will not work.

    I hope this helps, please let me know!

    Regards,

    David

    If this has been helpful
    - Please click on the *Add Reputation button at the bottom left.

    Please mark your thread as SOLVED:
    - Click Thread Tools above your first post, select "Mark your thread as Solved".


  3. #3
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,914

    Re: SUMPRODUCT with several criteria

    try

    =SUMPRODUCT(--(ISNUMBER(1/$EG13:$FI13)+ISNUMBER(SEARCH($EG13:$FI13&"",REPT("X",10)))>0),--($EG13:$FI13<>""),$EG$9:$FI$9,$EG$3:$FI$3)
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

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

    Re: SUMPRODUCT with several criteria

    Quote Originally Posted by David A Coop View Post
    If you want to count the number of times a character is repeated in a string:
    =LEN(A1)-LEN(SUBSTITUTE(A1,"x",""))
    This is better than the COUNT(SEARCH()) combination you used as it returns the number of times "x" appears in the string.

    Now, if you expand this to =IF(LEN(A1)-LEN(SUBSTITUTE(A1,"x",""))>=LEN(A1),1,0) you add a test to see if there are characters OTHER THAN X in the string. If so, as in the case of "LUX", it will return 0.

    Note, this will only work where there is x, xx, xxx etc. If there are spaces anywhere, the test will not work.

    I hope this helps, please let me know!

    Regards,

    David
    hmm... I think the "LUX" case makes it unnecessarily complex. How about if it is supposed to take all cells into account that contain an "x" no matter if it is a word such as "LUX" or if there are spaces in between and all cells that contain POSITIVE numbers so excluding everything below zero and zero itself?

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

    Re: SUMPRODUCT with several criteria

    Quote Originally Posted by nflsales View Post
    try

    =SUMPRODUCT(--(ISNUMBER(1/$EG13:$FI13)+ISNUMBER(SEARCH($EG13:$FI13&"",REPT("X",10)))>0),--($EG13:$FI13<>""),$EG$9:$FI$9,$EG$3:$FI$3)
    It DOES count negative numbers (even though it shouldn't) and DOES NOT count "x"s with a space somewhere (even though it should)

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

    Re: SUMPRODUCT with several criteria

    Quote Originally Posted by esbencito View Post
    It DOES count negative numbers (even though it shouldn't) and DOES NOT count "x"s with a space somewhere (even though it should)
    Just realised that it does NOT count words with "x" which is awesome! just negative numbers need to be removed (including 0) and "x"s with a space somewhere INCLUDED... is that feasible? Or does the space/s make it too difficult?

  7. #7
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,914

    Re: SUMPRODUCT with several criteria

    then try
    Please Login or Register  to view this content.

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

    Re: SUMPRODUCT with several criteria

    Impressive!! That works just fine!

    So one last thing... how would I apply the same to an IF(OR formula rather than a SUMPRODUCT? I have a combination of both, but it does not seem to work for the example below.

    Please Login or Register  to view this content.

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

    Re: SUMPRODUCT with several criteria

    it basically runs a different calculation depending on if one of the criteria is met. If the cell EG13 contains e.g. "x", " x", "xx", "xxx", "5", "10" etc. it runs the SUMPRODUCT formula, if not, such as "Lux", "-2", "-8", "Fox" etc. it SUMs a different cell range.

  10. #10
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,554

    Re: SUMPRODUCT with several criteria

    Assuming that the formula is used in a single cell, as opposed to be dragged across and/or down, it would seem that you could use:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Let us know if you have any questions.
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

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

    Re: SUMPRODUCT with several criteria

    Yup, that works! Just for my learning, could you explain what
    Please Login or Register  to view this content.
    does exactly?

  12. #12
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,554

    Re: SUMPRODUCT with several criteria

    It checks to see if the value in EG13 is numeric returning either true or false. The formula then goes on to see if the value in EG13 might be x or a grouping of x's and adds those results together using Boolean logic (T + T = T, F + F = F, T + F = T) The final part of the first sumproduct checks to see if the value of EG13 is greater than zero (alpha values will be). This part is multiplied using boolean logic (T * T = T, F * F = F, T * F = F) I hope this makes sense.
    A good way to see what the formula is doing is to use the Evaluate Formula feature (on the Formulas tab in the 2010 version).
    I used that particular fragment because it had been used in post #8 so I thought there might provide continuity with what was already known. Doing a bit of testing it seems that ISNUMBER(EG13) would yield the same results as would ISNUMBER(EG13:FI13) used instead of ISNUMBER(1/EG13:FI13).
    I believe that you'll get the same overall results with:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Let us know if you have any questions.

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

    Re: SUMPRODUCT with several criteria

    Quote Originally Posted by JeteMc View Post
    It checks to see if the value in EG13 is numeric returning either true or false. The formula then goes on to see if the value in EG13 might be x or a grouping of x's and adds those results together using Boolean logic (T + T = T, F + F = F, T + F = T) The final part of the first sumproduct checks to see if the value of EG13 is greater than zero (alpha values will be). This part is multiplied using boolean logic (T * T = T, F * F = F, T * F = F) I hope this makes sense.
    A good way to see what the formula is doing is to use the Evaluate Formula feature (on the Formulas tab in the 2010 version).
    Thanks for clarifying the Boolean logic, highly appreciated! Always good to learn new stuff

    I used that particular fragment because it had been used in post #8 so I thought there might provide continuity with what was already known. Doing a bit of testing it seems that ISNUMBER(EG13) would yield the same results as would ISNUMBER(EG13:FI13) used instead of ISNUMBER(1/EG13:FI13).
    I believe that you'll get the same overall results with:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    I also tried the formula without the
    Please Login or Register  to view this content.
    and simply used
    Please Login or Register  to view this content.
    instead, and it seems to indeed return the same results. Just wanted to check with you if there's anything I was missing if I remove it!

  14. #14
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,554

    Re: SUMPRODUCT with several criteria

    If that resolves the issue please take a moment to mark the thread as 'Solved' using the thread tools link above your first post. I hope that you have a blessed day.

+ 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. Replies: 3
    Last Post: 04-21-2015, 07:45 AM
  2. [SOLVED] Multiple criteria SUMPRODUCT (3 criteria) Excel 2003
    By lelrich in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-10-2014, 01:58 PM
  3. Replies: 6
    Last Post: 08-04-2013, 11:53 AM
  4. Replies: 5
    Last Post: 04-20-2012, 08:54 AM
  5. Replies: 2
    Last Post: 05-25-2010, 06:55 PM
  6. Sumproduct to sum with two criteria
    By firefiend in forum Excel General
    Replies: 3
    Last Post: 02-19-2010, 02:08 PM
  7. Sumproduct with 5 criteria
    By jeffg in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-29-2007, 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