Gross profit is revenue minus cost: =B1-B2. Gross profit margin is that profit as a share of revenue: =(B1-B2)/B1, or =B3/B1 if the profit is already in B3.
Format the result cell as a percentage with Ctrl+Shift+%, or you’ll see 0.4 instead of 40%. The distinction worth getting right is margin versus markup — they use the same profit figure but a different denominator. Margin divides by the selling price (=(Price-Cost)/Price), markup divides by the cost (=(Price-Cost)/Cost).
An item bought at 60 and sold at 100 has a 40% margin but a 67% markup, so quoting one when you mean the other misprices the product. To work backwards from a target margin to a price, use =Cost/(1-Margin) — a 40% margin on a cost of 60 needs a price of 100. And guard against a zero revenue with =IFERROR((B1-B2)/B1,0), since dividing by zero returns #DIV/0!.
In Excel, if you want to calculate the gross profit margin (the gross profit as a percentage of the revenue), you need a formula. And in this tutorial, we will learn to write it.

Write the Formula to Get the Gross Profit (Margin and Ratio)
Below are the steps to write this formula:
- First, enter the equal to (=) operator in a cell and type an opening parenthesis.
- After that, refer to cell B1 where you have the Revenue.
- Next, enter the minus operator, and refer to the cost (B2). For gross profit, this is the cost of the goods you have sold.
- In the end, enter the closing parenthesis, then the divide operator, and refer to the revenue cell again. And hit Enter to get the result.

The moment you hit Enter, it returns the gross profit margin in the result. The formula returns a decimal (like 0.4), so format the cell as a percentage (Ctrl + Shift + %) to see it as 40%.

=(B1-B2)/B1 =(Revenue – Cost) / Revenue
You can also calculate the gross profit in one cell and the margin in another cell.

In the above example, we have separated the profit and the profit margin percentage into two different cells.
Gross Profit
=Revenue – Cost =B1-B2
Gross Profit Margin
= Gross Profit / Revenue =B3/B1
Net Profit Margin
The gross profit margin only takes away the cost of the goods sold. If you want the net profit margin, subtract all the other expenses (like rent, salaries and taxes) as well. With the revenue in B1, the cost in B2 and the other expenses in B4, the formula would be:
=(B1-B2-B4)/B1
Profit Margin vs Markup
Margin divides the profit by the revenue, while markup divides the profit by the cost. So, for a revenue of 5000 and a cost of 3000, the margin is 40%, but the markup is 66.67%:
=(B1-B2)/B2
Find the Price for a Target Margin
If you know the cost and the margin you want, divide the cost by 1 minus the margin. For a cost of 3000 and a 40% margin, you need a price of 5000:
=B2/(1-40%)
Just adding 40% to the cost (3000 * 1.4 = 4200) gives a 28.57% margin, not 40%, which is a common mistake.
When the Revenue Is Zero
If the revenue cell is empty or 0, the formula returns #DIV/0!. To show a blank instead, check the revenue first:
=IF(B1=0,"",(B1-B2)/B1)
And when the cost is more than the revenue, you get a negative margin (like -20%), which means a loss.
Frequently Asked Questions
What is a good profit margin?
It depends on the industry, so compare your margin with businesses like yours and with your own past months, rather than with one fixed number.
How do I calculate the margin for a whole column?
Put the revenue and cost of each product in a row, enter the formula in the first row, and drag it down. As the references are relative, each row uses its own revenue and cost.
How do I get the average margin of all products?
Don’t average the margin percentages. Divide the total profit by the total revenue instead, so bigger products count more, like =(SUM(B2:B10)-SUM(C2:C10))/SUM(B2:B10).
Written by
Puneet Gogia
Microsoft MVP — Excel · Founder, Excel Champs
Twelve years of teaching Excel, and a decade before that using it as a data analyst. Every tutorial here is written from a file I actually built.