+ Reply to Thread
Results 1 to 2 of 2

Find all number combinations in a data set that add up to a specific number

  1. #1
    Registered User
    Join Date
    03-05-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    5

    Find all number combinations in a data set that add up to a specific number

    I have attached an example. If I have a set of numbers such as the one attached, is it possible to create a formula that will show me all the combinations of numbers that add up to 55.52? In the attached I have highlighted in different colours all the number combinations that add up to 55.52. The numbers highlighted in blue appear within more then one combination. Is there a formula that can do this for me, instead of randomly adding numbers hoping they add up to 55.52.

    If you could please assist.

    Thank you.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Find all number combinations in a data set that add up to a specific number

    Excel does not have a single, built in formula for this.

    With the proper spreadsheet design, Solver can often find "a" combination that adds up to a target value. This usually involves a helper column containing 1's and 0's, a sumproduct function, and a constraint in the Solver model to force the helper column to "binary" values. You could run Solver several times with different starting combinations and probably get several different results, but I think it will be rather difficult to know when you have found "all possible" combinations.

    I think the best approach will be to develop and test an algorithm for trying multiple combinations. I expect this should be designed to be better than "randomly adding number", but should be performed in a systematic way. This isn't the kind of programming I do, so I'm not good with the details, but I might try something like:

    1) Sort the data. I expect this will be easier with the data sorted. The block containing values greater than target (>55.52) can be ignored, because all of your values appear to be positive. Sorting the data will allow you to quickly identify which block of values will need to be considered and which block of values can be ignored.
    2) With the data sorted, identify the largest value <= target value (34.65 in the sample data set). Subtract this from the target value (55.52-34.65). Test for "completion" (is this result 0, greater than 0, or less than 0). This will tell you if this is a solution, still a potential solution, or an invalid solution.
    3a) Some programmers in some programming languages will use a strategy called "recursion". If the result from 2 is still a potential solution, they will take the difference (55.52-34.65) and make it a new "target value", go back into step 2 with this new target value, and keep recursively calling the routine (keeping track of where they are at in the overall problem), until they find a solution or find an invalid solution. It is a fairly advanced technique that requires adequate programming skill (and not all languages can call routines recursively). It can also be a powerful tool for these kinds of problems.
    3b) If you are not up to tackling this using recursion, one will usually set up some kind of loop structure that will perform the same steps and checks to identify valid combinations and reject invalid combinations.
    4) Work out all of the details and store results.

    This is certainly not a trivial programming exercise.

    Less efficient but easier to program might be a more "brute force" method where you sum up all possible combinations (I would still include a sort and exclude all values > target), then identify which ones = target. Developing this kind of algorithm would center mostly on programming well established algorithm for developing combinations/permutations (see http://en.wikipedia.org/wiki/Permuta...e_permutations). I would be tempted to use this if I did not want to use VBA (or other programming language) so that I was limiting myself to worksheet functions only.

    I'm sure there are other possible approaches. As this seems to be a somewhat common kind of problem, I expect there are programming texts that have formalized different algorithms for this kind of thing (I'm not sure where to find such discussions, though).
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

+ 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. How to autosum numerous data in a column and find a specific number.
    By ExcelQuestionHelp in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-26-2013, 12:42 PM
  2. Find Specific Combinations of Data
    By jxel in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-04-2010, 02:28 PM
  3. find all combinations of cells that add up to certain number
    By AD in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 11-18-2005, 09:35 AM
  4. [SOLVED] find all combinations of cells that add up to certain number
    By AD in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-17-2005, 03:55 PM
  5. [SOLVED] find all combinations of cells that add up to certain number
    By AD in forum Excel General
    Replies: 1
    Last Post: 11-17-2005, 03:40 PM

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