COGS calculator: the cost of goods sold formula, with a worked example

Published · Updated · 12 min read

Dylan Arnaud, founder of Datafuji

Cost of goods sold (COGS) is the direct cost of the products a company sold during a period: what it paid to buy or make them, excluding selling and administrative costs. COGS = beginning inventory + purchases − ending inventory.

A distributor that starts the year with €1,980k of inventory, buys €14,620k and ends with €2,100k has a COGS of €14,500k: on €23,500k of revenue, that leaves €9,000k of gross profit, a 38.3% gross margin.

Calculate your cost of goods sold

The calculator gives cost of goods sold, gross profit, gross margin and days inventory outstanding for a month, a quarter or a year. Days inventory outstanding is how many days, on average, goods stay in inventory before they are sold: average inventory ÷ COGS × 365, or 2,040 ÷ 14,500 × 365 ≈ 51 days for the example company. Enter inventory at cost at the start and end of the period, purchases for the same period and, to see the margin, net revenue.

A reseller leaves the labor and production field at 0. Amounts are in thousands of euros (€k), excluding sales tax or VAT; any currency works the same way. The default values are those of a fictitious distribution company.

Periodic method · whole company or a product line · your figures stay in your browser
Cost of goods sold
€14,500k
available €16,600k − ending inventory
Gross profit
€9,000k
revenue − COGS
Gross margin
38.3%
COGS is 61.7% of revenue
Days inventory outstanding
51 days
average inventory €2,040k

Of €16,600k of goods available for sale, €2,100k is still on the shelves: the other €14,500k went out with the sales and is the period’s COGS. It absorbs 61.7% of revenue and leaves €9,000k of gross profit, a gross margin of 38.3%.

What is cost of goods sold (COGS)?

Cost of goods sold is the cost, at purchase or production price, of the goods it sold during the period. Goods bought but still in inventory are not part of it: they remain an asset until they are sold.

The idea fits in one rule: costs follow the goods. IAS 2, the international standard on inventories, says it in its own words. When inventories are sold, their carrying amount “shall be recognised as an expense in the period in which the related revenue is recognised.”

A typical scenario: a business owner reads their bank statement for March, sees €1,200k paid to suppliers and concludes that goods cost €1,200k that month. But part of what was paid restocked the warehouse, and part of what was sold came from stock bought in February. COGS sorts this out.

The company in our example is fictitious; its figures are the calculator’s default values. A midsize distributor starts the year with €1,980k of inventory and buys €14,620k of goods, excluding sales tax or VAT. It ends the year with €2,100k of inventory and €23,500k of net revenue.

COGS, cost of sales, cost of revenue

The same line has several names. US retailers and distributors say cost of goods sold; companies reporting under IFRS usually say cost of sales; software and service businesses say cost of revenue or cost of services. The calculation behind each name is the one below.

How do you calculate cost of goods sold?

The COGS formula is beginning inventory plus purchases minus ending inventory. For a manufacturer, purchases are replaced by the cost of goods manufactured in the period; both formulas need inventory valued at cost.

Goods available for sale
  = beginning inventory
  + net purchases
  + freight-in and duties
  + production costs

COGS = goods available
  − ending inventory

Gross profit = net revenue
  − COGS

Gross margin = gross profit
  ÷ net revenue

This is the periodic method: you count what is left and deduce what went out. The Internal Revenue Service (IRS), the US tax authority, asks sole proprietors for exactly this sequence in Part III of Schedule C, lines 35 to 42:

Schedule C lineWhat it holdsExample company (illustration)
35Inventory at beginning of year€1,980k
36Purchases less cost of items withdrawn for personal use€14,620k
37Cost of labor (not paid to yourself)€0
38Materials and supplies€0
39Other costs€0
40Add lines 35 through 39€16,600k
41Inventory at end of year€2,100k
42Cost of goods sold: line 40 minus line 41€14,500k

Lines 37 to 39 are where a manufacturer puts its production costs; a reseller leaves them empty. On a real Schedule C, amounts are in dollars.

A worked example: the distributor’s year

With the calculator’s default values:

Goods available
  = 1,980 beginning inventory
  + 14,620 purchases
  + 0 freight-in + 0 production
  = €16,600k

COGS = 16,600 − 2,100 ending
  = €14,500k

Gross profit = 23,500 − 14,500
  = €9,000k

Gross margin = 9,000 ÷ 23,500
  = 38.3%

COGS ÷ revenue = 61.7%

Two bars to scale show where the €16,600k of goods available ended up.

Bars to scale, in thousands of euros. First bar: goods available for sale, €16,600k, made of beginning inventory €1,980k and purchases €14,620k. Second bar, same length: cost of goods sold €14,500k, which went out with the sales, and ending inventory €2,100k, still on the shelves. COGS = 1,980 + 14,620 − 2,100 = €14,500k.Bars to scale, in thousands of euros. First bar: goods available for sale, €16,600k, made of beginning inventory €1,980k and purchases €14,620k. Second bar, same length: cost of goods sold €14,500k, which went out with the sales, and ending inventory €2,100k, still on the shelves. COGS = 1,980 + 14,620 − 2,100 = €14,500k.
Of €16,600k of goods available, €2,100k is still in stock: the other €14,500k is the year’s cost of goods sold.

The company bought €14,620k but expensed only €14,500k: the €120k difference is the inventory build-up, from €1,980k to €2,100k. It is cash spent that will become cost next year, when those goods are sold.

The formula for a manufacturer

A manufacturer adds one step. It first calculates the cost of goods manufactured (COGM), the production cost of the units finished in the period, then applies the same formula to its finished goods inventory. Take a fictitious workshop, in €k:

Production costs
  = 1,200 materials used
  + 800 direct labor
  + 600 production overhead
  = 2,600

COGM = 150 work in progress
    at start + 2,600
  − 170 work in progress at end
  = 2,580

COGS = 400 finished goods
    at start + 2,580
  − 380 finished goods at end
  = 2,600

Materials used are themselves purchases adjusted for the change in raw materials inventory. Our cost price calculator shows how production overhead is allocated to each product.

What is included in cost of goods sold?

COGS includes everything it took to get the goods into salable condition and location: purchase price net of discounts, inbound freight, import duties, non-recoverable taxes and, for a manufacturer, direct labor and production overhead. Selling and administrative costs stay out.

IAS 2 draws the line in two paragraphs. Under paragraph 11, the costs of purchase “comprise the purchase price, import duties and other taxes (other than those subsequently recoverable by the entity from the taxing authorities)”. Transport, handling and other costs directly attributable to the acquisition are added, and trade discounts and rebates are deducted. Paragraph 16 then lists what must be excluded.

CostIn COGS?Why
Purchase price, net of trade discounts and rebatesYesCost of purchase (IAS 2.11)
Freight-in, handling, import dutiesYesDirectly attributable to the acquisition
Sales tax collected, recoverable VATNoNot a cost: passed on or recovered
Direct labor and production overheadYes, for a manufacturerCosts of conversion (IAS 2.12)
Abnormal waste of materials or laborNo, expensed directlyExcluded from inventory (IAS 2.16)
Storage after purchaseNo, unless needed in productionExcluded (IAS 2.16)
Freight-out, sales commissions, advertisingNoSelling costs (IAS 2.16)
Office rent, management salariesNoAdministrative overhead (IAS 2.16)

For a reseller, the usual trap is freight. Freight-in raises the cost of the goods; freight-out is a selling expense. Mixing the two moves gross margin without changing net income.

What about a service company?

A service company has no goods, but it has direct costs: the hours of the consultants billed, subcontractors, hosting for a software product. These form its cost of sales or cost of services. Whatever the name, the rule stays the same: only costs tied to what was delivered in the period.

Where does COGS go on the income statement?

COGS is the first expense on the income statement, right below net revenue; revenue minus COGS gives gross profit. Operating expenses (selling, general and administrative) come next and are deducted from gross profit to reach operating income.

The waterfall of the example company’s year:

Waterfall to scale, in thousands of euros, for the example company’s year. Net revenue €23,500k. Cost of goods sold takes €14,500k, 61.7% of revenue. Gross profit is €9,000k, a gross margin of 38.3%. Operating expenses (selling, general and administrative) come next, below gross profit.Waterfall to scale, in thousands of euros, for the example company’s year. Net revenue €23,500k. Cost of goods sold takes €14,500k, 61.7% of revenue. Gross profit is €9,000k, a gross margin of 38.3%. Operating expenses (selling, general and administrative) come next, below gross profit.
COGS takes €14,500k of €23,500k of revenue: the €9,000k left must cover every other expense.

Most US companies present their income statement this way. Some companies instead show expenses by nature: purchases, change in inventory, staff costs. Then there is no COGS line, and you rebuild it from purchases and the change in inventory.

COGS vs. operating expenses

The difference matters for decisions. COGS moves with volume: sell 10% more goods, and it rises by about 10%. Most operating expenses do not, at least in the short term. Our break-even calculator builds on this split between variable and fixed costs.

Gross margin and markup are two readings of the same gross profit: 9,000 ÷ 23,500 = 38.3% of revenue, or 9,000 ÷ 14,500 = 62.1% of cost. Our margin calculator converts one into the other and sets a selling price.

How do FIFO, LIFO and average cost change COGS?

When purchase prices change, the method used to value inventory decides which costs go into COGS and which stay in stock. FIFO, weighted average cost and LIFO give three different gross profits on the same goods and the same sales.

Take one item, in euros (not thousands): 100 units bought at €10, then 100 at €12, so €2,200 of goods available. The company sells 150 units.

  • FIFO (first in, first out) charges the oldest units first: 100 × €10 + 50 × €12 = €1,600 of COGS, €600 left in stock.
  • Weighted average cost charges every unit at €2,200 ÷ 200 = €11: 150 × €11 = €1,650, €550 in stock.
  • LIFO (last in, first out) charges the newest units first: 100 × €12 + 50 × €10 = €1,700, €500 in stock.
Bars to scale for one item. Goods available: 100 units bought at €10 and 100 units at €12, €2,200 in total; 150 units are sold. FIFO charges the older €10 units first: COGS €1,600, ending inventory €600. Weighted average cost of €11: COGS €1,650, ending inventory €550. LIFO charges the newer €12 units first: COGS €1,700, ending inventory €500. The total is always €2,200.Bars to scale for one item. Goods available: 100 units bought at €10 and 100 units at €12, €2,200 in total; 150 units are sold. FIFO charges the older €10 units first: COGS €1,600, ending inventory €600. Weighted average cost of €11: COGS €1,650, ending inventory €550. LIFO charges the newer €12 units first: COGS €1,700, ending inventory €500. The total is always €2,200.
The €2,200 is split differently: with rising prices, LIFO puts €100 more into COGS than FIFO.

The methods do not change the cash spent, only when it becomes an expense. Over the life of the stock, all three expense the same €2,200.

Which methods are allowed?

IAS 2 requires specific identification for items that are not interchangeable and, for the others, permits only FIFO or weighted average cost (§23 and §25): LIFO is not among them. US tax law allows LIFO. A company that uses LIFO for its federal tax return must also use it in the financial reports it gives shareholders and creditors. This is the LIFO conformity rule of section 472(c) of the Internal Revenue Code. It elects LIFO by filing Form 970.

Whatever the method, keep it from one year to the next. Switching changes COGS without any change in the business, and changing an accounting method for tax purposes requires the IRS’s consent (Pub 538).

How do you record cost of goods sold?

Under a perpetual system, each sale moves the cost of the goods from inventory to COGS as it happens. Under a periodic system, purchases are booked as they arrive and COGS is calculated at the end of the period from a stock count.

In a perpetual system, the ERP (the company’s management software) records two entries for each sale: debit accounts receivable and credit revenue; debit COGS and credit inventory. COGS is known every day, at the cost the system holds for each item.

In a periodic system, the books show purchases during the period. At the period-end close, the change in inventory adjusts them: ending inventory goes into the balance sheet and beginning inventory comes out. Purchases plus the decrease in inventory, or minus its increase, equal COGS. That is the calculator’s method.

Even a perpetual system needs a physical count. Theft, breakage and data-entry errors make the book inventory drift from what is on the shelves, a gap called shrinkage. The count corrects the inventory, and the difference goes into COGS.

What is a good COGS percentage of revenue?

No standard sets a good COGS ratio: it depends on the industry and on what the company adds to the goods it sells. Public gross margin statistics give the order of magnitude, and your own month-to-month trend says more than any average.

Aswath Damodaran, a finance professor at NYU Stern, publishes the gross margin of US listed companies by industry each January. COGS as a share of revenue is 100% minus that gross margin:

Industry (US listed companies)FirmsGross marginCOGS % of revenue
Retail (grocery and food)1526.3%73.7%
Retail (automotive)3422.0%78.0%
Retail (distributors)6230.6%69.4%
Retail (general)2333.2%66.8%
Restaurants6432.2%67.8%
Food processing7823.2%76.8%
Machinery10537.5%62.5%
Apparel3556.9%43.1%
Software30971.7%28.3%
All industries except financials4,82234.4%65.6%

These are listed companies, and each one draws the line between COGS and operating expenses its own way: read them as orders of magnitude, not targets. For retailers, the US Census Bureau’s Annual Retail Trade Survey publishes gross margin as a percentage of sales by type of store.

The example company, at 61.7% of revenue and a 38.3% gross margin, is a distributor: the closest row is Retail (distributors), at a 30.6% gross margin, and wholesalers in its own line are a better comparison than stores. A ratio that drifts by one or two points from month to month is the signal to watch: on €23,500k of revenue, one point of gross margin is worth €235k a year.

Which mistakes distort cost of goods sold?

Most COGS errors come from inventory, not purchases: ending inventory counted too high or too low moves gross profit by exactly the same amount. Cutoff errors, mixed freight and inconsistent valuation methods come next.

The effect of a count error of €100k on the example company:

Two cards. Correct count: ending inventory €2,100k, COGS €14,500k, gross profit €9,000k. Count overstated by €100k, for example goods counted twice: ending inventory €2,200k, COGS €14,400k, gross profit €9,100k, overstated by €100k. The next period starts with €100k too much beginning inventory, so its COGS is €100k too high: the error reverses.Two cards. Correct count: ending inventory €2,100k, COGS €14,500k, gross profit €9,000k. Count overstated by €100k, for example goods counted twice: ending inventory €2,200k, COGS €14,400k, gross profit €9,100k, overstated by €100k. The next period starts with €100k too much beginning inventory, so its COGS is €100k too high: the error reverses.
Each euro of inventory counted too high is a euro of gross profit that does not exist, until the next period takes it back.
  • Treating purchases as COGS. Without the change in inventory, the example company would have shown €14,620k instead of €14,500k: a gross margin of 37.8% instead of 38.3%.
  • Poor cutoff. Goods received on December 31 but invoiced in January are in the count without being in purchases: COGS falls. The reverse happens with goods invoiced before they arrive.
  • Inventory at selling price. Inventory is valued at cost. Counting it at selling price inflates ending inventory by the margin and shrinks COGS.
  • Obsolete inventory left at cost. Under IAS 2, inventory is carried at the lower of cost and net realizable value (the expected selling price minus the costs to finish and sell it); for US tax, Pub 538 allows the lower of cost or market. A write-down for goods that will no longer sell at cost goes into the period’s expenses.
  • Different methods in different months. Average cost in one ERP, FIFO in a spreadsheet: margins become impossible to compare.

How do you track COGS every month in Power BI?

Monthly COGS needs a monthly inventory value: either a perpetual system that values stock at every movement, or a month-end count. With that, a Power BI report gives COGS and gross margin by month, product line and customer.

In Power BI, the calculation fits in a few measures written in DAX, Power BI’s formula language. Inventory is a balance: it is read at a date, not added up over a period. With a purchases table, an inventory snapshot table by month-end and a date table:

Purchases =
  SUM ( Purchases[Amount] )

Ending inventory =
  CALCULATE (
    SUM ( Stock[Value] ),
    LASTDATE ( 'Date'[Date] )
  )

Beginning inventory =
  CALCULATE (
    [Ending inventory],
    PREVIOUSDAY (
      FIRSTDATE ( 'Date'[Date] )
    )
  )

COGS =
  VAR BI = [Beginning inventory]
  VAR EI = [Ending inventory]
  RETURN
    IF (
      NOT ISBLANK ( BI )
        && NOT ISBLANK ( EI ),
      BI + [Purchases] - EI
    )

The beginning inventory measure reads the day before the period starts: the previous month-end, for a month, a quarter or a year. When either inventory is missing, such as the month after the last loaded count or the current year, the COGS measure stays blank instead of counting the whole inventory as consumed. If your ERP posts COGS on each sale, use that table directly: it is more precise and gives COGS by product.

The most useful views are the gross margin by month against budget, by product line, and the gap between book inventory and the count. Our guide to the financial dashboard shows where these sit among the finance KPIs, and the inventory turnover calculator uses the same COGS to measure how long goods stay in stock.

Frequently asked questions

Is COGS an expense?

Yes. Cost of goods sold is an expense, recognized in the same period as the revenue from the goods it relates to. It is not an operating expense in the usual sense: it sits above gross profit, while selling, general and administrative expenses sit below it. Until the goods are sold, the same cost is an asset, inventory, on the balance sheet.

Is COGS the same as cost of sales?

Mostly. Companies that sell goods say cost of goods sold; IFRS financial statements and many service companies say cost of sales; software and service businesses often say cost of revenue. All three name the direct cost of what was sold in the period, the figure subtracted from revenue to get gross profit.

Does COGS include shipping?

Freight-in, the cost of bringing goods to your warehouse, is part of their purchase cost and therefore of COGS once they are sold. Freight-out, the cost of delivering to customers, is a selling expense under IAS 2, which excludes selling costs from inventory. Companies classify outbound shipping differently: check the accounting policy note.

Can COGS be negative?

No. A negative result means the inputs are wrong: usually ending inventory counted too high, purchases posted to the wrong period, or inventory counted at selling price. COGS can be very low for a service company or a month with almost no sales, but it can never fall below zero. The calculator flags the case.

Does COGS include labor?

Only the labor that makes the goods. A manufacturer’s direct labor and production overhead are costs of conversion under IAS 2 and go into inventory, then into COGS when the goods are sold. Schedule C line 37 asks for the cost of labor, not including amounts paid to yourself. Sales and office staff stay out of COGS.

Let’s talk about your reporting.

A 30-minute video call with Dylan Arnaud. You come away with a clear scope and a fixed price.

Dylan Arnaud, Power BI consultant and founder of Datafuji
Dylan ArnaudFounder · your single point of contact