• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Search for the best match through amounts to achieve a certain total.

Ronald

Member
Hello everyone,

My question is if you know a way to search through an array of amounts to try to match a certain value.

Example:

array:

123.45
32.65
567.43
2134.56
23.56
40.21
Amount I try to match: 56.21

Result: it shows that rows 2 and 5 match my amount (or within an mismatch range, e.g. the same result if my search amount was 56)

Do you maybe have a way to achieve this?

Regards,

Ronald.
 
Hi Ronald,

Can you walk us through the logic of why rows and and 5 are the best? How many combinations are allowed (can we take 3 items, or just 2)?
 
Sorry if I wasn't clear enough.
Row 2 and 5 match the amount I'm looking for.
Row 2: 32.65 + row 5: 23.56 = 56.21

The amount of combinations is not really an issue, if I at least have one (in more than 90% that will suit)

Background (why):
I get big amounts that customers pay for they orders (this includes many orders) and want to have the best match to this paid amount from the list of open invoices.
I know, they should specify order/invoice nr. etc. but that's indeed the ideal world :)

Hope this clarifies.
 
Thanks Hui.

Pity enough Solver doesn't work properly in this case. It match very illogical amounts leaving too much difference (despite of various tweeks).
And option 2 is paid :-( (beside a trial version that works very well)
 
Thanks Lori, looks promising.
I tried to extend the whole thing to have 100 rows and column 4 & 5 included applying your instructions but only got #VALUE! errors :-(

Can I maybe ask you to extend it for me so it works from row 3 (as now) to row 100 (i.e. of 8)?

Regards,

Ronald.
 
Unfortunately there's a theoretical limit on the size of the dataset with such a set-up of 20 entries. And even at 18/19 entries Excel may well run out of resources, in my experience.

With that sort of number, you would be best advised to seek a VBA-based solution.

Regards
 
Ronald, with the maximum 20 entries this took about 6 seconds to calculate the closest 10 matches - which is relatively quick considering it's calculating a matrix of 21 million values (this is helped by using a single array formula approach). But as XOR LX says you will run into difficulties extending beyond this as the number of possibilities to check grows exponentially.

Given 100 values to test, you will need to restrict the number of possibilities somehow. If you're willing to use a sum consisting of up to 4 of the entries that could be doable using a VBA program but it will likely become too large beyond that.
 
Back
Top