+ Reply to Thread
Results 1 to 8 of 8

Array Formula with Conditions Not Working

  1. #1
    Forum Contributor
    Join Date
    03-26-2015
    Location
    Cookeville, TN
    MS-Off Ver
    Excel 365
    Posts
    202

    Array Formula with Conditions Not Working

    I'm having issues trying to get an array formula to work properly.

    Simplified explanation: I'm working with a sheet of data (Orders) for work orders, with columns for workorder number, description, charge type, amount, etc. There can be multiple entries (charges) for a single workorder, for example charge type of "Parts" on one row, "Labor" on another row, "Refund" on another row, etc. There could also be several rows (for the same workorder) that are all for "Parts". On a separate Summary sheet, I need to sum, for each workorder, total parts, total labor, etc.

    This would be simple, EXCEPT for that fact that sometimes the workorder number is MISSING from its column in the Orders sheet. But fortunately, the description field usually contains the workorder number (interspersed with other text). My client therefore wants me to also sum (for example) the total costs for "Parts" where the workorder column is blank, but the target workorder number (123456, for example) appears anywhere in the description.

    There is a range name (such as Orders_Amounts) assigned to each column in the Orders data sheet. For starters, I wrote an array formula to simply sum ALL the amounts where the target workorder number (in cell A2 of my Summary sheet) appears anywhere in the description:
    Please Login or Register  to view this content.
    This does indeed give me a correct total. However, I then tried to limit the sum to only include "Parts":
    Please Login or Register  to view this content.
    This now simply gives me a ZERO result (although I've confirmed that every single row with the target workorder number does indeed show "Parts" under charge type).
    Each of the named ranges is for a complete column, so the rows of each are equal. What am I doing wrong?
    Last edited by Merf; 07-31-2020 at 06:16 AM. Reason: Clarify Post Title

  2. #2
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Need Help with Array Formula

    So you have 3 columns, in which 2 columns are criteria, 1 column is Amount, time together row by row, then sum all.
    1st criteria range:
    ISNUMBER(SEARCH(TEXT($A2,"0"),Orders_Descriptions)) return 1/0 if match/dont match
    2nd criteria range
    (Orders_ChargeTypes="Parts") return 1/0 if match/dont match

    Then using SUMPRODUCT to sum all rows those =1*1*Amount

    Please Login or Register  to view this content.
    Quang PT

  3. #3
    Forum Contributor
    Join Date
    03-26-2015
    Location
    Cookeville, TN
    MS-Off Ver
    Excel 365
    Posts
    202

    Re: Need Help with Array Formula

    Sorry, that doesn't work. I still get a zero result. Even using SUMPRODUCT to get the sum of ALL entries (where description contains the workorder number):
    Please Login or Register  to view this content.
    doesn't work (result is zero). So this is worse than my original array formula.
    Last edited by AliGW; 07-31-2020 at 06:07 AM. Reason: Please don’t quote unnecessarily!

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,817

    Re: Need Help with Array Formula

    Administrative Note:

    We would very much like to help you with your query, however the thread title does not really convey what your request is about. Tell us what you are trying to do with the formula.

    Please take a moment to amend your thread title. Make sure that the title properly explains your request. Your title should be explicit and not be generic (this includes function names used without an indication of what you are trying to achieve).

    Please see Forum Rule #1 about proper thread titles and adjust accordingly. To edit the thread title, open the original post to edit and then click on Go Advanced (bottom right) to access the area where you can edit your title.

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

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

    Re: Need Help with Array Formula

    Quote Originally Posted by Merf View Post
    =SUMPRODUCT(ISNUMBER(SEARCH(TEXT($A2,"0"),Orders_Descriptions)),Orders_Amounts)
    doesn't work (result is zero). So this is worse than my original array formula.
    Not really, though it's no more efficient... in the above you need to coerce your Boolean array either discretely, or via multiplication with second array, i.e.:

    =SUMPRODUCT(ISNUMBER(SEARCH(TEXT($A2,"0"),Orders_Descriptions))+0,Orders_Amounts)
    or
    =SUMPRODUCT(ISNUMBER(SEARCH(TEXT($A2,"0"),Orders_Descriptions))*Orders_Amounts)

    So, if (either of) the above generate the same result as your initial array and yet, with extra condition, the below generates 0:

    =SUMPRODUCT(ISNUMBER(SEARCH(TEXT($A2,"0"),Orders_Descriptions))*(Orders_ChargeTypes="Parts"),Orders_Amounts)

    then this tells us that there are no values ="Parts"

    you could then apply a TRIM to see if that's the problem (i.e. leading/trailing spaces)

    =SUMPRODUCT(ISNUMBER(SEARCH(TEXT($A2,"0"),Orders_Descriptions))*(TRIM(Orders_ChargeTypes)="Parts"),Orders_Amounts)

    or, consider another SEARCH - mindful of fact you could get false positives, at which point I would manipulate the strings accordingly, ie..

    =SUMPRODUCT(ISNUMBER(SEARCH(TEXT($A2,"0"),Orders_Descriptions)*SEARCH(" Parts "," "&Orders_ChargeTypes&" ")),Orders_Amounts)
    (note with the above the ISNUMBER can be applied to the product of the SEARCHes, need not be applied to each SEARCH separately)
    Last edited by XLent; 07-31-2020 at 07:55 AM. Reason: added font for ease of reference

  6. #6
    Forum Contributor
    Join Date
    03-26-2015
    Location
    Cookeville, TN
    MS-Off Ver
    Excel 365
    Posts
    202

    Re: Array Formula with Conditions Not Working

    I finally got everything to work OK.

    The key is that, although the documented syntax for SUMPRODUCT shows a COMMA between the various terms, apparently you must enclose logical terms in parentheses and use an ASTERISK (rather than a comma) between them.

    Not quite sure WHY this is so, but it apparently works!

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,817

    Re: Array Formula with Conditions Not Working

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

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

    Re: Array Formula with Conditions Not Working

    Quote Originally Posted by Merf View Post
    ...although the documented syntax for SUMPRODUCT shows a COMMA between the various terms, apparently you must enclose logical terms in parentheses and use an ASTERISK (rather than a comma) between them.

    Not quite sure WHY this is so, but it apparently works!
    Hi, refer to the point re: coercion in my prior post -- so you can use either:

    =SUMPRODUCT((boolean array)+0,numeric_range)
    or
    =SUMPRODUCT((boolean)*numeric_range)

    both do the same thing in that they are coercing the logicals (boolean array) to their native XL integer equivalents of 1 (TRUE) and 0 (FALSE)

    If the arrays in your SUMPRODUCT share the same dimensions it is generally a good idea to split the logicals from the "numeric" range, so using the first rather than second approach

    the reason for this is to ape the behaviour of SUMIF, so assume your "numeric" range also stored text values (incl. null strings from formulas), this:

    =SUMPRODUCT((boolean)*numeric_range) --> #VALUE!

    because when you explicitly coerce the numeric_range string it will generate an error, whereas:

    =SUMPRODUCT((boolean)+0,numeric_range) --> #

    will behave like SUMIF, you coerce the Booleans discretely, and the products themselves will ignore the non-numeric values

    the above is just a basic overview, there are good reasons to use * route (e.g. numbers stored as text, or arrays have different dimensions) but, hopefully, this sheds some light.

    edit: and so, in the case of two boolean arrays - rather than coerce separately you can multiple these together, and keep separate from the "numeric_range", e.g.

    =SUMPRODUCT((boolean)*(boolean),numeric_range)

    key is still that we're coercing the booleans discretely relative to the "numeric range" - for sake of robustness
    Last edited by XLent; 07-31-2020 at 10:13 AM.

+ 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. Array summing inventory of a specific part (array formula) EXCEL 2007
    By fdirosa in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-07-2018, 12:51 PM
  2. Replies: 3
    Last Post: 04-02-2016, 08:16 PM
  3. Can I make the row lookup array/range part in an array formula variable?
    By OLLY-7 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-18-2014, 09:06 AM
  4. Array formula + Array formula with criteria that lookups a Table
    By anrichards22 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-16-2013, 11:41 AM
  5. Replace hard coded array in formula with link to input array
    By David Brown in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 01-08-2011, 07:45 AM
  6. Converting 3x10 array to a 1X30 array to run a Match formula
    By NBVC in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-08-2009, 07:45 AM
  7. [SOLVED] Tricky array formula issue - Using array formula on one cell, then autofilling down a range
    By aspenbordr in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-27-2005, 11:05 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