+ Reply to Thread
Results 1 to 9 of 9

Efficient Array Formula Construction

  1. #1
    Mike Moore
    Guest

    Efficient Array Formula Construction

    Is there a better array formula construction than the one described below?

    I have two columns. Column A contains department designations (i.e. dept A,
    dept B, dept C, dept D, etc). Column B contains dollar amounts.

    The formula parameters are to sum multiple designated departments into one
    cell.

    I have the following formula developed:

    {=sum((a1:a100=dept a)*(b1:b100))+sum((A1:a100=dept c)*(b1:b100))}

    Instead of having two sum statements, can the formula be condensed to one
    sum statement? For example,

    {=sum((a1:a100=And(dept a, dept c))*(b1:b100))}

    I have tried the above formula, but could not get it to work.

    Second question - is it possible to set up the array formula to deal with
    conditions that change? For example, department A and department C belong
    to the Midwest region. However, next year department C belongs to the
    Southwest region and department B belongs to the Midwest region.

    I don't want to have to change hundreds of array formulas due to
    department changes.

    I have thought about using named ranges that designate a list of departments
    belonging to regions. However, I have been unsuccessful in this approach.



  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    If you create a named range of Midwest departments - midwest - then try

    =sumproduct(--isnumber(match(a1:a100,midwest,0)),b1:b100)

    which only requires ENTER

  3. #3
    Forum Contributor
    Join Date
    09-25-2004
    Posts
    269
    See if this helps.



    =SUMPRODUCT((A1:A100={"dept a","dept c"})*(B1:B100))



    I use to work with a guy name Mike Moore. Did you ever worked at El Monte California?

  4. #4
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    ....and to answer your first question, you can use the same formula without a named range, if you wish, by specifying an array of department names with the formula i.e.

    =sumproduct(--isnumber(match(a1:a100,{"dept A","dept B"},0)),b1:b100)

  5. #5
    Sandy Mann
    Guest

    Re: Efficient Array Formula Construction

    To answer your question:

    > Instead of having two sum statements, can the formula be condensed to one
    > sum statement? For example,
    >
    > {=sum((a1:a100=And(dept a, dept c))*(b1:b100))}
    >
    > I have tried the above formula, but could not get it to work


    You were nearly there, try the array entered formua:

    {=SUM((A1:A100={"Dept a","Dept c"})*(B1:B100))}

    --
    HTH

    Sandy
    In Perth, the ancient capital of Scotland

    [email protected]
    [email protected] with @tiscali.co.uk


    "Mike Moore" <[email protected]> wrote in message
    news:%237OX%[email protected]...
    > Is there a better array formula construction than the one described below?
    >
    > I have two columns. Column A contains department designations (i.e. dept
    > A, dept B, dept C, dept D, etc). Column B contains dollar amounts.
    >
    > The formula parameters are to sum multiple designated departments into one
    > cell.
    >
    > I have the following formula developed:
    >
    > {=sum((a1:a100=dept a)*(b1:b100))+sum((A1:a100=dept c)*(b1:b100))}
    >
    > Instead of having two sum statements, can the formula be condensed to one
    > sum statement? For example,
    >
    > {=sum((a1:a100=And(dept a, dept c))*(b1:b100))}
    >
    > I have tried the above formula, but could not get it to work.
    >
    > Second question - is it possible to set up the array formula to deal with
    > conditions that change? For example, department A and department C belong
    > to the Midwest region. However, next year department C belongs to the
    > Southwest region and department B belongs to the Midwest region.
    >
    > I don't want to have to change hundreds of array formulas due to
    > department changes.
    >
    > I have thought about using named ranges that designate a list of
    > departments belonging to regions. However, I have been unsuccessful in
    > this approach.
    >




  6. #6
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    Sorry, don't want to confuse you with multiple suggestions but....

    This formula, which only requires ENTER is, another way to go

    =SUM(SUMIF(A1:A100,{"dept a","dept b"},B1:B100))

    array entered, i.e. using CTRL+SHIFT+ENTER, you can also use the above with a named range

    =SUM(SUMIF(A1:A100,midwest,B1:B100))

  7. #7
    M Moore
    Guest

    Re: Efficient Array Formula Construction

    I understand the solution of . . . .

    =sumproduct(--isnumber(match(a1:100,midwest,0)),b1:b100)

    Now, I am going to throw one more issue into the problem.

    What if I have a third column containing text (such as "revenues" and
    "expense").

    I need to add all the revenues for all the midwest departments into one
    cell. Or, I need to add all the expenses for all the midwest departments
    into one cell.




    "Mike Moore" <[email protected]> wrote in message
    news:%237OX%[email protected]...
    > Is there a better array formula construction than the one described below?
    >
    > I have two columns. Column A contains department designations (i.e. dept
    > A, dept B, dept C, dept D, etc). Column B contains dollar amounts.
    >
    > The formula parameters are to sum multiple designated departments into one
    > cell.
    >
    > I have the following formula developed:
    >
    > {=sum((a1:a100=dept a)*(b1:b100))+sum((A1:a100=dept c)*(b1:b100))}
    >
    > Instead of having two sum statements, can the formula be condensed to one
    > sum statement? For example,
    >
    > {=sum((a1:a100=And(dept a, dept c))*(b1:b100))}
    >
    > I have tried the above formula, but could not get it to work.
    >
    > Second question - is it possible to set up the array formula to deal with
    > conditions that change? For example, department A and department C belong
    > to the Midwest region. However, next year department C belongs to the
    > Southwest region and department B belongs to the Midwest region.
    >
    > I don't want to have to change hundreds of array formulas due to
    > department changes.
    >
    > I have thought about using named ranges that designate a list of
    > departments belonging to regions. However, I have been unsuccessful in
    > this approach.
    >




  8. #8
    Forum Expert
    Join Date
    09-09-2005
    Location
    England
    MS-Off Ver
    2007
    Posts
    1,500
    Just expand the previous answers
    eg if revenue appears in column C
    =SUMPRODUCT((A1:A100={"dept a","dept c"})*(B1:B100))

    becomes
    =SUMPRODUCT((A1:A100={"dept a","dept c"})*(B1:B100)*(c1:c100="Revenue"))

    Regards

    Dav

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

    =sumproduct(--isnumber(match(a1:100,midwest,0)),b1:b100,--(c1:c100="revenue"))

+ 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