+ Reply to Thread
Results 1 to 17 of 17

Create an array from "True" only then perform Sumproduct???

  1. #1
    Registered User
    Join Date
    03-07-2011
    Location
    Detroit, MI
    MS-Off Ver
    Excel 2003, 2007, & 2010
    Posts
    52

    Create an array from "True" only then perform Sumproduct???

    So I have two dynamic arrays that I am trying to get the Sumproduct of the 1st actual value in the arrays, then the 2nd, etc. I am having an issue cause the IF statement I am using to generate the arrays leaves "False" values in the arrays rather than just starting and continuing building the array on "True" Values. Below is an example of what is happening vs. what I need to happen:

    False----1
    --1----False
    False--False
    False----2
    False--False
    --2----False
    False----3
    False--False
    --3----False

    A Sumproduct of these 2 arrays returns zero as it is trying to multiply the actual values by their "False" counterpart.

    Essentially I need the arrays to not include the "Falses" so they would end up looking like this.

    1 1
    2 2
    3 3

    Below is a sample of my current code. Any idea how I can go about getting the array to only return the true values and not Falses? Appreciate the help.

    {=SUMPRODUCT(IF($A$1:$O$1=1, $A$2:$O$2),IF($A$1:$O$1=2, $A$3:$O$3))}

    BTW this is crossposted here:

    http://www.mrexcel.com/forum/excel-q...ml#post4212628
    Last edited by drew.j.harrison; 07-13-2015 at 11:11 AM.

  2. #2
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: Create an array from "True" only then perform Sumproduct???

    Does this help? By telling False to do "" then it is not counted in the formula for MIN value.
    Please Login or Register  to view this content.
    Some people volunteer in soup kitchens or hospitals. I choose to make the world better by trying to help you with Excel. We're all learning.

    <---Click * Add Reputation for all helpful comments. It's like giving a smile.
    Forum Rules: How to mark your post [Solved] and have a happier, Excel enriched life.

  3. #3
    Registered User
    Join Date
    03-07-2011
    Location
    Detroit, MI
    MS-Off Ver
    Excel 2003, 2007, & 2010
    Posts
    52

    Re: Create an array from "True" only then perform Sumproduct???

    Sorry I misposted the formula originally. I am not using MIN. Below is my current formula.

    {=SUMPRODUCT(IF($A$1:$O$1=1, $A$2:$O$2),IF($A$1:$O$1=2, $A$3:$O$3))}

    I need the sumproduct of the arrays not the minimum values in the arrays.

    In the example given above it would look like this:

    1 X 1 = 1
    2 X 2 = 4
    3 X 3 = 9

    Sum = 14

    Really I am trying to create arrays of only the True values then perform a sumproduct of those arrays. Problem is the IF statement doesn't function that way. It just puts false in the array in place of the actual values that aren't true rather than ignoring them.
    Last edited by drew.j.harrison; 07-13-2015 at 11:22 AM.

  4. #4
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: Create an array from "True" only then perform Sumproduct???

    Can you post a spreadsheet of what you are trying to do? You can add it by going to "Go Advanced" and using the paperclip icon.

  5. #5
    Registered User
    Join Date
    03-07-2011
    Location
    Detroit, MI
    MS-Off Ver
    Excel 2003, 2007, & 2010
    Posts
    52

    Re: Create an array from "True" only then perform Sumproduct???

    I've attached an example that mimics what I am trying to do. The array configuration is a bit different than what I posted above but more accurately represents what I am looking to do. Thanks again for the help.

    Example Total Spend Sumproduct Calculation.xlsx

  6. #6
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: Create an array from "True" only then perform Sumproduct???

    This will give you the first value of location 1 and the first value of location 2 in the file you attached:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    03-07-2011
    Location
    Detroit, MI
    MS-Off Ver
    Excel 2003, 2007, & 2010
    Posts
    52

    Re: Create an array from "True" only then perform Sumproduct???

    Quote Originally Posted by nigelbloomy View Post
    This will give you the first value of location 1 and the first value of location 2 in the file you attached:
    Please Login or Register  to view this content.
    Unfortunately that is not what I am looking for. I am looking to multiply the Volume of Location 1 by the Price of Location 1 and Multiply the Volume of Location 2 by the Price of Location 2 and sum the two numbers.

    As I mentioned above the issue is I need the Array that is generated to only include the valid values.

    Currently the following code in the example I had attached:

    {=IF(B3:K3="Volume",B4:K4)}

    Generates the following Array:

    100
    FALSE
    FALSE
    FALSE
    FALSE
    200
    FALSE
    FALSE
    FALSE
    FALSE

    I need it to ignore the falses and generate the following array:

    100
    200

    I've attached an updated file that hopefully better explains/shows this.

    Example Total Spend Sumproduct Calculation.xlsx

  8. #8
    Valued Forum Contributor
    Join Date
    07-29-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2003/Excel 2010
    Posts
    534

    Re: Create an array from "True" only then perform Sumproduct???

    See if the attachment gives you the result you were looking for:

  9. #9
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: Create an array from "True" only then perform Sumproduct???

    This array formula gets the result you are lookng for, but it isn't pretty:
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    03-07-2011
    Location
    Detroit, MI
    MS-Off Ver
    Excel 2003, 2007, & 2010
    Posts
    52

    Re: Create an array from "True" only then perform Sumproduct???

    Quote Originally Posted by WHER View Post
    See if the attachment gives you the result you were looking for:
    Very clever. Works perfect. Thanks for the help!

    For those that didn't download the file the code is below:

    {=SUMPRODUCT(SMALL(IF(B3:K3="Volume",B4:K4,""),ROW(INDIRECT("1:"&COUNTIF(B3:K3,"Volume")))),SMALL(IF(L3:Q3="Price", L4:Q4,""),ROW(INDIRECT("1:"&COUNTIF(L3:Q3,"Price")))))}

    Nigel,

    Your code also works but not for a dynamic range. Would need to keep adding iterations of the code for each row in the arrays (aka additional "location"). Appreciate the effort though. I was investigating something similar as this is close to how I've created lists of unique values in other sheets.

    Thanks all for the help!
    Last edited by drew.j.harrison; 07-13-2015 at 07:38 PM.

  11. #11
    Registered User
    Join Date
    03-07-2011
    Location
    Detroit, MI
    MS-Off Ver
    Excel 2003, 2007, & 2010
    Posts
    52

    Re: Create an array from "True" only then perform Sumproduct???

    Looks like I jumped on that solution too quickly. After messing with it some more I realized that it actually reorders the arrays from smallest to largest. Unfortunately this throws the data off quite a bit.

    Instead of what should be

    4 1
    3 2
    2 3

    giving you a sum product of 16

    You get

    2 1
    3 2
    4 3

    giving you a sum product of 20

    Back to the drawing board.

    I've attached an updated spreadsheet that shows what I am referring to.
    Last edited by drew.j.harrison; 07-13-2015 at 10:54 PM.

  12. #12
    Registered User
    Join Date
    03-07-2011
    Location
    Detroit, MI
    MS-Off Ver
    Excel 2003, 2007, & 2010
    Posts
    52

    Re: Create an array from "True" only then perform Sumproduct???

    Just solved on the cross posted thread. Thanks again guys for all the help. Below is the working code:

    {=SUMPRODUCT(INDEX(B4:Q4,1,N(IF(1,SMALL(IF($B$3:$Q$3="Volume",COLUMN($B$3:$Q$3)-MIN(COLUMN($B$3:$Q$3))+1),ROW(INDIRECT("1:"&COUNTIF($B$3:$Q$3,"Volume"))))))),INDEX(B4:Q4,1,N(IF(1,SMALL(IF($B$3:$Q$3="Price",COLUMN($B$3:$Q$3)-MIN(COLUMN($B$3:$Q$3))+1),ROW(INDIRECT("1:"&COUNTIF($B$3:$Q$3,"Price"))))))))
    }

  13. #13
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: Create an array from "True" only then perform Sumproduct???

    This also works.
    Please Login or Register  to view this content.
    Does anyone know why the N(if(1 section is required for row to return an array to small and the results of small as an array back to index? If I take either of those out then row doesn't return an array back to small or small will not pass the full array back to index.

    Side note. I did not know that Index could handle an array as the result of which column or row to look at. I will have to look at that more.

  14. #14
    Valued Forum Contributor
    Join Date
    07-29-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2003/Excel 2010
    Posts
    534

    Re: Create an array from "True" only then perform Sumproduct???

    One more that seems to "do the right thing", CSE entered
    Please Login or Register  to view this content.

  15. #15
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Create an array from "True" only then perform Sumproduct???

    Quote Originally Posted by nigelbloomy View Post
    This also works.
    Please Login or Register  to view this content.
    Does anyone know why the N(if(1 section is required for row to return an array to small and the results of small as an array back to index? If I take either of those out then row doesn't return an array back to small or small will not pass the full array back to index.

    Side note. I did not know that Index could handle an array as the result of which column or row to look at. I will have to look at that more.
    You might find this series of articles helpful. The construction you are using is among those discussed. You may have to do some searching from there.

    http://excelxor.com/2014/11/04/coerc...las/#more-2591

    Hope this helps.
    Dave

  16. #16
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: Create an array from "True" only then perform Sumproduct???

    Quote Originally Posted by FlameRetired View Post
    You might find this series of articles helpful. The construction you are using is among those discussed. You may have to do some searching from there.
    Excelxor has some great articles. Thank you finding this one for me.

  17. #17
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Create an array from "True" only then perform Sumproduct???

    @nigelbloomy

    You're welcome. Glad it helps.

+ 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: 1
    Last Post: 08-15-2014, 06:00 AM
  2. compare two excel sheets using macros and display the result in "true" or "false"
    By gayunana01 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-09-2012, 07:21 AM
  3. Replies: 5
    Last Post: 10-12-2010, 06:46 AM
  4. Replies: 5
    Last Post: 01-28-2010, 04:04 PM
  5. Replies: 7
    Last Post: 05-13-2006, 05:02 PM
  6. If changed array formula reduce ""\""\""\ - signs to #Missing, will it make ...
    By Maria J-son in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-05-2006, 08:25 AM
  7. [SOLVED] IF(VLOOKUP("MYDATA", MYNAME, 4) = 0, "TRUE", "FALSE")
    By Souris in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-17-2005, 01:05 AM

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