Formula for splitting profit and loss for every person I am looking for a formula to calculate even distribution of loss or profit between involved parties. Let's speak with some examples as I feel it will be easier.

Example 1

Person 1

Balance: 2,000,000
Supplies (investment): 70,000

Person 2

Balance: -260,000
Supplies (investment): 260,000

Person 3

Balance: -17,000
Supplies (investment): 84,000

Description

As we can see one person made profit in this example. To distribute everything evenly he should pay every person loss (so 259,000 to Person 2 and 17,000 to Person 3) and divide what's left by 3 and distribute that as well.

Example 2

Person 1

Balance: 2,000,000
Supplies (investment): 80,000

Person 2

Balance: 1,000,000
Supplies (investment): 150,000

Person 3

Balance: -900,000
Supplies (investement): 900,000

Person 4

Balance: -150,000
Supplies (investment): 100,000

Description

As we can see two people here made profit so it gets trickier. We still want to distribute everything evenly. Easiest way I see is to sum all the negative balances (1,050,000 here), subtract that from profit (3,000,000 - 1,050,000 = 2,950,000) so everyone 737,500 / 4 so Person 2 has to give back a little from his balance (profit) and so does Person 1. Easiest would be to cumulate all profit in one account (e.g. Person 1) and make Person 1 split everything but it seems more work. 

Example 3

Person 1

Balance: -10,000
Supplies (investment): 50,000

Person 2

Balance: -20,000
Supplies (investment): 20,000

Person 3

Balance: -500
Supplies (investment): 500

Description

As we can see no-one made any profit but Person 1 earned 40,000 as he used 50,000 for supplies and  has only -10,000 in losses. So this 40,000 should be evenly distributed but according to their usage of supplies. 

Is that correct way of thinking? Is there a formula for splitting profit and loss?
Either I totally misunderstand the question, or this is just adding up numbers, there are no economic or mathematical principles involved. (In which case this is not the right SE for it.)

Denoting the "balances" by $b_1,b_2,...$ and the "supplies" by $s_1,s_2,...$ total profits are
$$
\Pi_{total} = \sum_i (b_i-s_i)
$$
You want everyone to end up with a proportional share of this, so that in the end they have
$$
\frac{s_i}{\sum_i s_i} \Pi_{total}.
$$
To compensate for their investment, each person should get
$$
x_i = s_i + \frac{s_i}{\sum_i s_i} \Pi_{total}.
$$
One can verify that
$$
\begin{align*}
\sum_i x_i &amp; = \sum_i s_i + \sum_i\frac{s_i}{\sum_i s_i} \Pi_{total} \\
&amp; = \sum_i s_i + \Pi_{total} = \sum_i b_i
\end{align*}
$$
so we made no mistakes, you can indeed give people their values $x_i$.