The formula
To keep a set share of the price as profit, divide your cost by whatever is left once that share is taken out.
price = cost ÷ (1 − margin)
A $30 item at a 40% target margin: $30 ÷ 0.6 = $50. Check: $50 − $30 = $20, and $20 is 40% of $50.
When fees come off the price
Marketplaces and payment providers usually take a percentage of the sale. That fee rises with your price, so it can't simply be added to the cost. It comes out of the divisor alongside your margin. Fixed amounts, like a per-order fee, are added to the cost first.
price = (cost + fixed fees) ÷ (1 − margin − fee %)
Same $30 item, 40% margin, a 12% commission and a $1 order fee: ($30 + $1) ÷ (1 − 0.40 − 0.12) = $64.58. Out of that, fees take $8.75, the item costs $30, and $25.83 is profit, which is 40% of the price.
Ignore the fees and you'd charge $50, then lose $7 of it to the marketplace, leaving a 26% margin instead of 40%.
Adding VAT
If you charge VAT, it goes on top of the price you just worked out, and it's paid on to the tax office. With 23% VAT the $64.58 price becomes $79.44 on the shelf. Your margin is still measured on the $64.58.
Margins that can't be reached
If your target margin plus percentage fees reach 100%, there's no price that works: every extra dollar you charge is eaten by fees and margin. The calculator tells you when you've hit that wall.