# Calculating dependent primary and secondary margins

Given a particular unit price (UP) and the desired final price (FP), I need to calculate a primary (PM) and secondary (SM) margin to achieve the final price (FP) such that the profit (SP [secondary profit]) of the secondary margin (SM) will be 50% of the profit (PP [primary profit]) from the primary margin (PM).

Take the following example:

$$UP = 125, FP = 312.5, PM = 50, SM = 20$$

$${({UP \over 1-({PM/100})}) \over 1-({SM/100})} = FP$$

$${({125 \over 1-({50/100})}) \over 1-({20/100})} = 312.5$$

$${250 \over 0.8} = 312.5$$

$$PP = ({UP \over 1-({PM/100})}) - UP = ({125 \over 1-({50/100})}) - 125 = 125$$

$$SP = FP - (UP + PP) = 312.5 - 250 = 62.5$$

$${SP \over PP} = {62.5 \over 125} = 0.5$$

Given the above example, if PM and SM were unknown, how could they be calculated?

$$D = 0.5$$

$$PP + (PP/D) = FP - UP$$

$$SP = {(FP - UP) \over (1+D)/D}$$

$$PP = FP - UP - SP$$

$$SM = {100SP \over FP}$$

$$PM = {100PP \over UP + PP}$$

Solving for SM & PM using $$UP = 125, FP = 312.5, D = 0.5$$

$$SP = {(312.5 - 125) \over (1+0.5)/0.5} = {187.5 \over 3} = 62.5$$

$$PP = 312.5 - 125 - 62.5 = 125$$

$$SM = {100 \cdot 62.5 \over 312.5} = 20$$

$$PM = {100 \cdot 125 \over 125 + 125} = 50$$

$$({SP \over PP} = D) = ({62.5 \over 125} = 0.5)$$