Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel Gross Margin Formula: Step-by-Step Guide

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To calculate gross margin in Excel, subtract cost of goods sold (COGS) from revenue, then divide the result by revenue: =(B2-C2)/B2, where B2 holds revenue and C2 holds COGS. Format the result as a percentage. Gross margin tells you what share of each sales dollar survives after direct costs, so it is the number to watch when pricing products or comparing product lines.

What You'll Need

  • A spreadsheet with at least two columns of clean data: revenue (or selling price) per row and COGS per row.
  • Confidence that both figures cover the same period and the same unit — for example, revenue and cost for one product in one month, not revenue for a year against cost for a quarter.
  • Decision on what belongs in COGS: materials, direct labour, packaging, shipping to the customer, payment processing fees. Exclude rent, salaries of admin staff, marketing and other overhead — those belong below the gross margin line.
  • Excel (desktop or the web app) or any spreadsheet tool that accepts the same formulas. Cell references and the percentage format button behave the same across current versions, though menu labels can differ slightly by version, device or region.

Step-by-Step

  1. Set up your columns. In row 1, type headers: Product in A1, Revenue in B1, COGS in C1, Gross Profit in D1, Gross Margin in E1. Keeping one figure per column makes every formula below a simple copy-down.
  2. Enter one row of test data. For example, a product that sells for 50 (B2) with direct costs of 30 (C2). Do not include currency symbols when you type; you can format them later.
  3. Calculate gross profit. In D2, enter =B2-C2. This returns 20. Gross profit is the dollar amount left after direct costs; gross margin is that amount expressed as a share of revenue.
  4. Calculate gross margin. In E2, enter =(B2-C2)/B2 or, using the profit you just made, =D2/B2. Both give 0.4, which is 40%.
  5. Format as a percentage. Select E2 and click the % button on the Home tab, or press Ctrl+Shift+% (Windows) or Cmd+Shift+% (Mac). The cell now shows 40%. If it shows 4000%, the number was already multiplied upstream — check that B2 contains 50, not 5000.
  6. Copy the formulas down. Select D2:E2, grab the fill handle (the small square at the bottom-right corner of the selection) and drag down, or double-click it to fill to the last used row. Every row now recalculates with its own revenue and cost.
  7. Add a total row. Below your data, sum revenue and COGS with =SUM(B2:B10) and =SUM(C2:C10). Then calculate margin on the totals: =(SUM(B2:B10)-SUM(C2:C10))/SUM(B2:B10). This blended figure is usually what you want for the business as a whole, because it weights high-volume products correctly.
  8. Label and lock the output. Give the total margin cell a bold label such as Blended Gross Margin. If you plan to share the file, select the input cells and use Format Cells > Protection to unlock them for editing, then protect the sheet — so the formulas cannot be accidentally overwritten.

Common Mistakes

  • Dividing by cost instead of revenue. Cost-based markup and revenue-based margin are different numbers. A 50 sale with 30 cost is a 40% margin but a 66.7% markup. If your margin figures look suspiciously high, you probably divided by the wrong column.
  • Mixing overhead into COGS. Adding rent or admin salaries to COGS turns gross margin into operating margin, which makes comparisons against industry benchmarks meaningless.
  • Blank or zero revenue cells. Any row with zero revenue returns a #DIV/0! error. See the troubleshooting section for a clean fix.
  • Text stored as numbers. Figures imported from another system often arrive left-aligned as text. Formulas then return #VALUE! or silently treat the value as zero. Check that numbers are right-aligned by default.
  • Percentages typed as numbers. Entering 0.4 as 40 or 40% as 4000 breaks your math. Enter decimals (0.4) or use the percent sign consistently, then apply the percentage format.
  • Averaging row percentages. The average of each product's margin is not the company margin; small products get the same weight as best-sellers. Always total first, then divide.

Tips

  • Use a formula you can read at a glance: =IFERROR((B2-C2)/B2,"") hides errors in empty rows and keeps reports tidy.
  • Turn your range into an Excel Table (Ctrl+T) so formulas auto-fill to new rows and totals stay accurate as data grows.
  • Compare margin and margin percentage side by side. Two products can share a margin percentage while one contributes far more profit in dollars.
  • Create a quick what-if column: enter a target price in a spare cell and calculate =(Price-Target_COGS)/Price to see how pricing or supplier changes move your margin before you commit.
  • Use conditional formatting on the margin column to highlight anything below your target, so problem products stand out without manual review.
  • If you need a margin from markup, use Margin = 1 - (1/(1+Markup)). Converting a 25% markup gives a 20% margin.

Troubleshooting

You see #DIV/0!. One or more revenue cells are zero or blank. Wrap the formula in IFERROR as shown above, or filter out the empty rows before calculating.

You see #VALUE!. At least one cell in the formula holds text rather than a number. Select the column and use Data > Text to Columns, or retype the numbers. Check for stray spaces and non-breaking characters copied from websites.

The result appears as 0.4 instead of 40%. The formula is correct but the formatting is not. Click the percent button or use Format Cells > Percentage and set the decimal places you need.

The number is enormous or negative. A cost greater than revenue is a genuine loss, so check the inputs. A value in the thousands usually means a currency was typed with a symbol and Excel interpreted the text differently, or the formula references the wrong column.

Copying the formula breaks it. If row 3's formula points somewhere unexpected, the reference was not anchored. Use $ signs for fixed cells, like =$B$2, when you want a reference to stay put.

Nothing recalculates automatically. The workbook may be set to manual calculation. On the Formulas tab, choose Calculation Options and switch back to Automatic.

Frequently Asked Questions

What is the formula for gross margin in Excel?

Gross margin equals (revenue minus COGS) divided by revenue. In cell form, =(B2-C2)/B2, then format the cell as a percentage.

What is the difference between gross margin and gross profit?

Gross profit is the dollar amount left after direct costs (revenue minus COGS). Gross margin is the same result expressed as a percentage of revenue, which makes it easier to compare products of different sizes.

Should I include shipping and payment fees in COGS?

Yes, if they are directly tied to selling the product — outbound shipping and card processing fees are commonly included. Keep general overhead such as office rent out of COGS.

How do I calculate the margin for the whole business?

Sum total revenue and total COGS separately, then divide the difference by total revenue. Do not average the individual row percentages, because that weights small products the same as large ones.

Can I convert a markup percentage into a margin percentage?

Yes. Margin = 1 minus (1 divided by (1 plus markup)). A 25% markup becomes a 20% margin; a 100% markup becomes a 50% margin.

Does the formula work on Excel for the web and mobile?

Yes. The formula syntax is identical everywhere. On mobile, the percent formatting option is under the cell formatting menu rather than a toolbar button, but the calculation is unchanged.