Formula to calculate how much to add or subtract to keep totals even

MrHoyt

New Member
Joined
Oct 30, 2024
Messages
5
Office Version
  1. 2010
Platform
  1. Windows
Say I am tasked with either adding or taking away oranges from three different bins, depending on the day. Each bin can only hold up to 100 oranges, and the idea is to try to keep all three bins with equal amounts of oranges after I am done, or as close as possible. (can use fractions of oranges to keep things easier)

The problem is right now each bin is out of sorts:

A1- Where I would enter the total amount of oranges I need to add that day. Lets say I need to add 100 oranges today.
A2- Where I would enter the total amount of oranges that I need to remove that day. Lets say I do not need to remove any oranges today.

C1- Bin 1 currently has 30 oranges. D1 shows in percentage how full Bin 1 is, which is 30%
C2- Bin 2 currently has 50 oranges. D2 shows in percentage how full Bin 2 is, which is 50%
C3- Bin 3 currently has 80 oranges. D3 shows in percentage how full Bin 3 is, which is 80%

Is there a formula I could use that would tell me how much to distribute to get the bins balanced out?
(My math shows me that I need to add 56.666 to Bin 1, 36.666 to Bin 2 and 6.666 to Bin 3)
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Try this.
In short. you need to get the total current number of oranges (100 to add minus zero to remove plus the total of all the bins) = 260
Divide that by the number of bins (3) = 86.67 to be in each bin after distribution.
Subtract the number in each bin from 86.67 to find the number to add/remove to each bin (it may be negative, indicating a removal).

Book1
ABCDEF
1 Add/remove
2To add100Bin 13056.66667
3To remove0Bin 25036.66667
4Bin 3806.666667
5
Sheet1
Cell Formulas
RangeFormula
F2:F4F2=($B$2-$B$3+SUM($E$2:$E$4))/COUNT($E$2:$E$4)-$E2
 
Upvote 0
Myall_blues, thank you for your help with this. I forgot to mention that I am not able to remove the oranges from the fullest bin(s) to help balance things out. What you have provided would help but the times it wants to remove from the fullest bin(s) to make the bins 100% balanced makes this not a perfect solution.

I was trying to use the MIN, MEDIAN, and MAX functions to determine how to allocate the oranges in the scenario I described for 100 oranges being added.
Bin 3(Max) - Bin 1(Min) = Add 50 oranges to Bin 1.
Bin 3(Max) - Bin 2(Median)= add 30 oranges to Bin 2.
All three bins are now at 80. I have 20 oranges left over to evenly distribute to all three bins, which makes the end total 86.6667 per bin.

There will be times I won't be able to get all three bins perfectly balanced, but I'm thinking this way or something like it has me moving in the right direction?
 
Upvote 0
I am not able to remove the oranges from the fullest bin(s) to help balance things out.
What rule defines bins in the plural situation here? One could argue in the simple three bin situation described that both the bin with 80 and the bin with 50 are the fullest bins (plural). Or is this a multi-line production scenario where each line has a singular ’fullest bin’?
 
Upvote 0
Instead of bins think of the three storage locations as warehouses. Typically marketing is either buying oranges to put into these "warehouses" to sell at a later date, or selling oranges which requires us to move them out of storage.

It's best practice to be diligent to keep inventory equal across all three warehouses so as not to need the calculation I am looking for. But you have the human element involved in this storage process. Or for business reasons it might make more sense to only put oranges into two of the warehouses with the idea to "square up" later. Also while it is possible to pull oranges from one warehouse to put into the other to balance out their inventory, it is almost never used because there is a cost associated with doing this.

About every week or so there is a new protocol management sends out for us to follow to try to balance out the warehouses. I was hoping to have something to use on a daily basis.
 
Upvote 0
I think I found a solution using an IF statement in a helper column that I can hide, and a very lengthy, multiple IF statement in the Add/Remove column 😬 It's not pretty but from I can see it works.

=IF(E2=MAX($E$2:$E$4),0,MAX($E$2:$E$4-E2))
1730530487764.png


Basically the Helper column shows the difference between the Max bin and the other bins. The Helper column is then used to help with calculations in the Add/Remove column.


=IF(IF($B$2<SUM($F$2:$F$4),(($B$2-SUM($F$2:$F$4))/2)+F2,(($B$2-SUM($F$2:$F$4))/3)+F2)<0,0,IF($B$2<SUM($F$2:$F$4),(($B$2-SUM($F$2:$F$4))/2)+F2,(($B$2-SUM($F$2:$F$4))/3)+F2))
1730530536182.png


If To Add is less than the SUM of the Helper column, then subtract To Add from the SUM of the Helper column and divide this by 2 and add then add the Helper amount
If To Add is not less than the SUM of the Helper column, then subtract To Add from the SUM of the Helper column and divide this by 3 and add then add the Helper amount
If this results in a negative number then this results in a 0 in the Add/Remove Column
If this does not result in a negative number than the IF statement basically repeats itself.


1730532610653.png


What do you think? Also, I only worked with the To Add, would have to make some small tweaks for the To Remove part. Or utilize VBA to not have such a long IF statement?😅
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,177
Members
452,615
Latest member
bogeys2birdies

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