Algorithm to pair positive and negative numbers and deal with residuals

widdbar

New Member
Joined
Mar 26, 2020
Messages
1
Office Version
  1. 365
Platform
  1. MacOS
I have the following problem:

I have a number of data entries with following fields ID, Name, Category, Amount - currently in Excel columns. The aggregate of Amount will equal zero, ie there are positives and negatives - but it will not necessarily equal zero for each Category.

I need an algorithm which will pair off IDs in the following way:
  • For each Category try and pair off within the category if possible.
  • Create the minimum matches as possible - ie match an ID with Amount of +3, to one with -3 if possible. But if not, can split - so +1 of it could go to an ID of -1 and +2 to a different ID with -2.
  • Repeat for all the categories and match any residuals across categories as needed
In the end I want a list showing the amount of each +ID going to each -ID.

Hope that makes sense!
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi Widdbar,
welcome to the forum. Could you add something like a screenshot? An example of what your input and desired output plus a show of your efforts so far would be great.
Thanks in advance,
Koen
 
Upvote 0

Forum statistics

Threads
1,214,635
Messages
6,120,660
Members
448,975
Latest member
sweeberry

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top