+ Reply to Thread
Results 1 to 8 of 8

Complex conditional summing formula...ideas?

  1. #1
    Registered User
    Join Date
    12-09-2009
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    4

    Complex conditional summing formula...ideas?

    Hi all,

    This is my first post! I have been racking my brain as to how to tackle this problem...any help would be greatly appreciated

    Basically I have data arranged as follows:

    Please Login or Register  to view this content.
    I need to sum the data in column "Dat2" only for "Col1" values of "A" where there are any non-blank(non-zero) values in both "Dat1" and "Dat2" for ANY Col1 value associated with a given "Indx" value...

    In this case, the correct result would be 30 (10 from Indx 1, 20 from Indx 2, 0 from Indx 4). Indx 5 and 3 are not considered since data appears in only one of the Dat columns.

    Because of the nature of my sheet, I need to be able to do this in a SINGLE cell (i.e. have only a single formula do all the operations). I have already got the correct result using a multi-celled solution. The Dat columns extend onward, so I have to be able to drag the formula each time I get a new Dat column. Also, each Indx value will have three Col1 values always in the same order (it's actually a pivot table in my sheet). I'd prefer not to have to write a VBA function to do this if I don't have to...

    Any Excel Ninja extrodinaires out there up for the challenge??? Thanks so much in advance for your help!

    Cheers,

    Andrew

  2. #2
    Registered User
    Join Date
    12-09-2009
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Complex conditional summing formula...ideas?

    One more thing...I need to be able to follow this up for summing B and C values as well...

  3. #3
    Valued Forum Contributor JeanRage's Avatar
    Join Date
    03-02-2009
    Location
    Nice, France
    MS-Off Ver
    Excel 2003
    Posts
    705

    Re: Complex conditional summing formula...ideas?

    Hi,

    See attached sample ...

    HTH
    Attached Files Attached Files

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Complex conditional summing formula...ideas?

    If I've understood I would say any native formula will be inefficient (very) and most likely volatile... given the inclusion test for any "A" Dat1 value is that within any group values must exist for at least row one in Dat1 and Dat2
    (ie Col1 is at that juncture irrelevant)

    If helpers are not permitted I have to say that IMO a UDF would make sense - esp. if the calculation is to be repeated.
    Last edited by DonkeyOte; 12-09-2009 at 01:24 PM.

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Complex conditional summing formula...ideas?

    FWIW whilst others come up with something incredible here would be one UDF approach

    Please Login or Register  to view this content.
    called from a cell along the lines of

    Please Login or Register  to view this content.
    where

    G2: criteria value eg A

    B2:B15 is your Col1 range of values

    C2:D15 represents your Data values

    2 is the parameter denoting which column to sum within the dat value range

    So to sum B simply change G2 from A to B (or run another formula)

    To sum column C rather than D change 2 to 1

    etc...

    NOTE:
    the final parameter is optional - should you choose to omit this the function will sum all columns simultaneously (ie default col. index of 0)
    --so if omitted using example of A you would get output of 65 (35+30)

  6. #6
    Registered User
    Join Date
    12-09-2009
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Complex conditional summing formula...ideas?

    Quote Originally Posted by JeanRage
    Hi,

    See attached sample ...

    HTH
    Thanks, though the 10 from Indx 1 must also be included because data exists for that index for Col1 values of B and C in Dat1...
    Last edited by DonkeyOte; 12-09-2009 at 03:06 PM. Reason: added quote to avoid confusion

  7. #7
    Registered User
    Join Date
    12-09-2009
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Complex conditional summing formula...ideas?

    Quote Originally Posted by DonkeyOte View Post
    FWIW whilst others come up with something incredible here would be one UDF approach...
    Wow thanks so much for this! I'll try it out. If it works, can it be extended to multiple Dat1 columns? I.e. lets say I need to do the same thing but to check if any data exists across a variable number of non-contiguous columns?

    Thanks a lot!
    Last edited by DonkeyOte; 12-09-2009 at 02:47 PM. Reason: reduced quote to nec. part

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Complex conditional summing formula...ideas?

    Quote Originally Posted by acovato
    can it be extended to multiple Dat1 columns? I.e. lets say I need to do the same thing but to check if any data exists across a variable number of non-contiguous columns?
    First I'd recommend checking that it does what you expected/wanted over a fairly basic and standard setup (ie per your sample) !

    Extending over contiguous ranges shouldn't be a massive issue, however, non-contiguous ranges generally translates as "significantly more complex" (require ParamArray).

    As I say - post back and let us know how you got in with the earlier code in your simplified environment ...

    If the basic principle is ok then by all means outline the most hideously complex scenario you can think of - pref. by means of sample file with desired results clearly illustrated (with proofs if poss.) and we'll see what we can all come up with.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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