+ Reply to Thread
Results 1 to 9 of 9

Count number of values required to sum to total

  1. #1
    Registered User
    Join Date
    05-30-2014
    Posts
    11

    Count number of values required to sum to total

    I've got a large data set (#8760 values taken at #8760 time points) listed in a column and I need to find out how many of the values i need to add together to reach a target value. However there are multiple target values (#280) and I need to perform the action for all #8760 time points.

    To understand the problem its probably best to look at the example sheet I've attached. The example sheet is a cut down version of my data set but shows what Im trying to achieve. The full data set has the Time point values running from 1 - 8760, each with an associated value and has the target values running from 280 - 1.

    I had created a very very long nested IF function (cut down version in the attached sheet), however, I ran up against the 64 nested IF function limit. Due to the nature of the data I do require more than 64 levels of nesting in order to reach the target value for all time points and all targets.

    Is there another way of doing this so I wont run into the 64 nesting limit?
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Count number of values required to sum to total

    Can you post the formula, so i can see what your up to?

    Reading your text I think a VLookup will solve your problem.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,939

    Re: Count number of values required to sum to total

    =LOOKUP(E$15,SUBTOTAL(9,OFFSET($D16,0,0,ROW($D16:$D$40)-ROW($D16)+1,1)),ROW($D16:$D$40)-ROW($D16)+1)+1
    Try this in Cell "E16" and copy across
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

  4. #4
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,939

    Re: Count number of values required to sum to total

    The above will not work with exact match
    Try this
    =IF(SUM($D16:$D$40)<E$15,"",LOOKUP(E$15,SUBTOTAL(9,OFFSET($D16,0,0,ROW($D16:$D$40)-ROW($D16)+1,1)),ROW($D16:$D$40)-ROW($D16)+1)+IF(LOOKUP(E$15,SUBTOTAL(9,OFFSET($D16,0,0,ROW($D16:$D$40)-ROW($D16)+1,1)))=E$15,0,1))

  5. #5
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Count number of values required to sum to total

    Also, this in E16 and copied across and down:

    =IFERROR(MATCH(TRUE,MMULT(0+(ROW($D16:$D40)>=TRANSPOSE(N(INDEX(ROW($D16:$D40),,)))),0+$D16:$D40)>=E$15,0),"")

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  6. #6
    Registered User
    Join Date
    05-30-2014
    Posts
    11

    Re: Count number of values required to sum to total

    Wow, thank you both for the rapid and effective replies. Both options work, however, CPU useage is extreme when copied into all 2452800 cells (280 columns x 8760 rows). Its actually more considerably processor use than when I used my (limited) nested if statements. Currently doing it for a fraction of the entire sheet takes several minutes. Is there a way to make it more resource efficient?

    I dont have the fastest PC int he world(32bit windows 7 OS, 4gb ram, intel i5 2.4ghz)

  7. #7
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Count number of values required to sum to total

    I think with that large a dataset you'd be best off considering a VBA solution.

    Perhaps if you re-post in the VBA section of this forum with a link to this thread.

    Regards

  8. #8
    Registered User
    Join Date
    05-30-2014
    Posts
    11

    Re: Count number of values required to sum to total

    Many thanks,

    Thread posted in vba/macro section @

    http://www.excelforum.com/excel-prog...ml#post3826215

  9. #9
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Count number of values required to sum to total

    Thanks for letting us know. It really does help a lot if links such as that are posted.

    Hopefully someone will be able to help you on that new thread soon.

    Regards

+ 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: 7
    Last Post: 10-10-2013, 09:13 AM
  2. Replies: 3
    Last Post: 06-12-2013, 10:53 PM
  3. Replies: 3
    Last Post: 10-27-2012, 04:16 AM
  4. Return location when values add to total required
    By tarquinious in forum Excel General
    Replies: 5
    Last Post: 08-31-2011, 10:28 AM
  5. Total values required for each week
    By mbruce3 in forum Excel General
    Replies: 2
    Last Post: 06-20-2011, 07:13 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