+ Reply to Thread
Results 1 to 11 of 11

Sumproduct of 2 columns, if one of 7 strings found in corresponding rows

  1. #1
    Registered User
    Join Date
    09-28-2015
    Location
    Groningen
    MS-Off Ver
    2010
    Posts
    5

    Sumproduct of 2 columns, if one of 7 strings found in corresponding rows

    Hi all,

    I can't get my head around the correct syntax for this type of formula:

    =SUMPRODUCT(SIGN(ISNUMBER(SEARCH({"454";"453";"452";"451";"254";"253";"252"};INDIRECT("'"&A51&"'!B3:B"&D51-1))));INDIRECT("'"&A51&"'!H3:H"&D51-1);INDIRECT("'"&A51&"'!"&C51&3&":"&C51&D51-1))

    or to simplify:

    =SUMPRODUCT(SIGN(ISNUMBER(SEARCH({"454";"453";"452";"451";"254";"253";"252"};B3:B69)));H3:H69;I3:I69)

    In column B there is a text (Type no.) that I want to scan for the occurrence (yes/no) of one of these 7 substrings, and for the rows that are returned, multiply columns H and I (price per item [H] times number of items [I]).
    In this way, the formula will return the total summed price for all items that match the search conditions.

    If I run this command without the array, so only for "254" for example, all goes well. Why doesn't it in this form?

  2. #2
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Sumproduct of 2 columns, if one of 7 strings found in corresponding rows

    I think it's the SIGN, it doesn't return as an array. And the ; within the array.

    Try ISNUMBER

    =SUMPRODUCT((ISNUMBER(SEARCH({"454","453","452","451","254","253","252"};B3:B69)))*H3:H69*I3:I69)

  3. #3
    Registered User
    Join Date
    09-28-2015
    Location
    Groningen
    MS-Off Ver
    2010
    Posts
    5

    Re: Sumproduct of 2 columns, if one of 7 strings found in corresponding rows

    Unfortunately that does not work. Within the Dutch locale I have to use ; instead of , because of regional settings. Within the array I'm using semi-colons as well.

    I've tried the same thing with a SUMIF statement, but that does not let me do any multiplication of rows within it's syntax; the sum_range criterion only allows a reference to a cell range, not a newly constructed array.

    Is there any other way to do this within one cell?

  4. #4
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Sumproduct of 2 columns, if one of 7 strings found in corresponding rows

    Did you Try it?
    I tested it on my machine with ; as list seperator.

    A constant array {} can use either , OR ; as it's seperator.

    Using , your {array} ends up arranged as columns like A1:G1
    Using ; your {array} ends up arranged as rows like A1:A7
    Last edited by Jonmo1; 09-28-2015 at 09:18 AM.

  5. #5
    Registered User
    Join Date
    09-28-2015
    Location
    Groningen
    MS-Off Ver
    2010
    Posts
    5

    Re: Sumproduct of 2 columns, if one of 7 strings found in corresponding rows

    I have tried it and Excel shows a syntax error; setting your machine to Dutch locale apparently does not allow , as a seperator. Any other tips?

  6. #6
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Sumproduct of 2 columns, if one of 7 strings found in corresponding rows

    OK, it's more than just list seperator issues then..

    This works when I set to Dutch(Belgium)

    =SUMPRODUCT((ISNUMBER(SEARCH({"454"\"453"\"452"\"451"\"254"\"253"\"252"};B3:B69)))*H3:H69*I3:I69)

  7. #7
    Registered User
    Join Date
    09-28-2015
    Location
    Groningen
    MS-Off Ver
    2010
    Posts
    5

    Re: Sumproduct of 2 columns, if one of 7 strings found in corresponding rows

    Your comment got me thinking and in my simplified example it works if I use TRANSPOSE() to get the column-wise array you are talking about!

    It works in the extended formula as well (with all my INDIRECT references), but only if I use * instead of ; for the sumproduct, and if I use the TRANSPOSE() function! Thanks

    Correct syntax therefore is:
    =SUMPRODUCT((ISNUMBER(SEARCH(TRANSPOSE({"454";"453";"452";"451";"254";"253";"252"});B3:B69)))*H3:H69*I3:I69)

    Can you explain why the * is needed instead of the ; and why this array needs to be transposed?

  8. #8
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Sumproduct of 2 columns, if one of 7 strings found in corresponding rows

    Quote Originally Posted by lennartvl View Post
    Can you explain why the * is needed instead of the ; and why this array needs to be transposed?
    See Post #4, but in my comments change , to /
    In Dutch, the 2 possible seperators for {constant arrays} are , and /

    So using , the {array} is arranged as columns like A1:G1
    Using / the {array} is arranges as rows like A1:A7

    Sumproduct requires all arrays to be of similar dimentions.
    When using , in the array, it was doing multiplicaiton of dissimilar dimensioned arrays like rows*columns = #Value! error.
    Transposing that range (or using / instead of ,) makes that {array} the same type of dimension rows*rows

    Also, they have different number of elements in each array, {} is 7 elements, whre H3:H69 is 67 elements.
    Sumproduct can't do that by itself.
    Changing the syntax to {}*H3:H69 makes it work, the math is done before sumproduct looks at it.
    Last edited by Jonmo1; 09-28-2015 at 09:46 AM.

  9. #9
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Sumproduct of 2 columns, if one of 7 strings found in corresponding rows

    Here's a better way to look at it.

    SEARCH(TRANSPOSE({"454","453","452","451","254","253","252"});B3:B69))

    This actualy becomes a 2 Dimensional array
    It does 7 searches for each value in B3:B69
    454-B3 | 453-B3 | 452-B3 | 451-B3 | 254-B3 | 253-B3 | 252-B3
    454-B4 | 453-B4 | 452-B4 | 451-B4 | 254-B4 | 253-B4 | 252-B4
    454-B5 | 453-B5 | 452-B5 | 451-B5 | 254-B5 | 253-B5 | 252-B5
    etc.

    So this becomes a 7 column 66 Row array
    Sumproduct can't multiply that with a 1 column 67 row array.
    So using the * forces excel to do that math internally before passing it's results to sumproduct.
    Last edited by Jonmo1; 09-28-2015 at 09:46 AM.

  10. #10
    Registered User
    Join Date
    09-28-2015
    Location
    Groningen
    MS-Off Ver
    2010
    Posts
    5

    Re: Sumproduct of 2 columns, if one of 7 strings found in corresponding rows

    Thanks for your elaborate explanation, it's clear now!

  11. #11
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Sumproduct of 2 columns, if one of 7 strings found in corresponding rows

    You're welcome.

+ 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. VBA to calculate the sumproduct on rows where a particular string is found.
    By Sttupendous in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-12-2014, 09:31 AM
  2. Replies: 3
    Last Post: 01-21-2014, 05:15 PM
  3. excel formula to search Multiple strings in several columns and return strings
    By krratna123 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-13-2013, 11:20 AM
  4. Replies: 1
    Last Post: 08-13-2013, 08:32 AM
  5. [SOLVED] Find variant matches from two columns and hide rows that are not found in the other
    By thelisa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-28-2013, 11:15 AM
  6. [SOLVED] Extract unique strings from excel cells across rows and columns
    By quedan in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 01-28-2013, 02:42 PM
  7. [SOLVED] Remove blank rows and columns in between strings
    By cruise.alter in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-09-2012, 02:02 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