The cost of goods sold formula is Beginning Inventory + Purchases − Ending Inventory = COGS. This guide walks Shopify operators through applying that formula in practice in 2026. It covers what to include in landed cost, what to exclude, and how 3PL fees, returns, and bundle SKUs distort the number when you run it straight from Shopify reports.

1What You'll Need

  • Shopify admin access with reports enabled
  • Inventory counts at the start and end of the period (from Shopify, Cin7, or your ERP)
  • Supplier invoices showing unit cost and inbound freight
  • 3PL invoices (receiving fees, storage, pick-pack) from ShipBob or your warehouse
  • Customs and duty entries for any imported goods
  • QuickBooks Online or Xero with an inventory asset account set up
  • Returns data from Shopify or your returns app (Loop, AfterShip)

2How Do You Define the Period and Pull Inventory Balances?

Pick the period you're calculating COGS for. Then pull two inventory snapshots: one at the start, one at the end. The formula only works if both balances use landed cost and the same costing method (FIFO, LIFO, or weighted average). Mixing methods between snapshots breaks the math entirely.

Most Shopify stores Ottit works with run COGS monthly. The starting balance for May is the ending balance from April. If books haven't been closed cleanly each month, the balances drift. The formula starts spitting out numbers that don't match physical reality.

Pull the inventory valuation report from Shopify (Reports > Inventory > ABC analysis or the inventory valuation export). If you run Cin7, DOSS, or another ERP as the source of truth, pull from there instead. Shopify's native inventory value is often unreliable. It uses the cost field on the variant, which many stores never update.

You'll know this worked when the ending inventory balance from the prior period exactly equals the beginning inventory balance for the current period. Both should be valued using the same costing method.

3How Do You Calculate Landed Cost for Purchases?

Purchases means the landed cost of inventory received during the period, not just the supplier invoice. Landed cost includes the unit price, inbound freight, customs duties, import fees, and any inspection or rework costs needed to make the product sellable. This is where most Shopify stores get COGS wrong.

Here's a typical landed cost calculation for a 5,000-unit purchase order from an overseas supplier:

Landed cost on a 5,000-unit PO
Supplier invoice (5,000 units × $4.20)$21,000
Ocean freight$3,800
Customs duty (7.5%)$1,575
Customs broker fee$425
Inbound trucking to 3PL$650
3PL receiving fee$550
Total landed cost$28,000
Per-unit landed cost$5.60

The supplier invoice was $4.20 per unit. The actual landed cost is $5.60 per unit, a 33% increase. Stores that book purchases at the supplier invoice amount understate COGS, overstate inventory, and run their margins on fantasy numbers.

You'll know this worked when every PO received in the period has a landed cost that ties to a supplier invoice plus all freight, duty, and receiving costs. The total flows into the inventory asset account on the balance sheet.

4What Belongs in COGS vs. Operating Expenses?

Not every cost related to selling a product belongs in COGS. The textbook formula treats COGS as the direct cost of goods sold during a period. For Shopify operators, the practical line is simple: costs to make a unit sellable belong in COGS. Costs to acquire or fulfill an order belong in operating expenses.

We've seen this pattern across 100+ Shopify stores: founders include processing fees and ad spend in COGS to make the number look bigger. Then they wonder why their gross margin looks worse than benchmarks. The table below shows how Ottit categorizes the most common Shopify expense types.

COGS vs. Operating Expense Categorization

Expense TypeGoes In COGS?Where It Belongs
Product unit cost from supplierYesCOGS — Product Cost
Inbound freight (factory to warehouse)YesCOGS — Freight In
Customs duties and import feesYesCOGS — Duty
3PL receiving and inspection feesYesCOGS — Fulfillment In
3PL storage feesNoOpEx — Warehouse
3PL pick, pack, and outbound shipNoOpEx — Fulfillment
Shopify Payments processing feesNoOpEx — Merchant Fees
Shopify subscription and appsNoOpEx — Software
Ad spend (Meta, Google, TikTok)NoOpEx — Marketing
Inventory shrinkage and damagesYesCOGS — Shrinkage
Returned-to-stock unit reversalYesCOGS reversal
CostBelongs in COGS?Where it goes
Product unit cost from supplierYesCOGS
Inbound freight to warehouseYesCOGS (capitalized into inventory)
Customs and dutyYesCOGS (capitalized into inventory)
3PL receiving feesYesCOGS
3PL storage feesSometimesCOGS or fulfillment expense
Pick and pack feesNo (typically)Fulfillment expense
Outbound shipping to customerNoFulfillment expense
Shopify Payments feesNoMerchant fees / contra-revenue
Shopify subscriptionNoSoftware expense
Klaviyo, Gorgias, Recharge feesNoSoftware expense
Returns shipping (inbound)NoReturns expense
Damaged/written-off inventoryYesCOGS adjustment

You'll know this worked when your chart of accounts has a clear COGS section that only contains product-related costs. Operating expenses should contain the merchant fees, software, and outbound fulfillment costs.

5How Do You Adjust for Returns, Damages, and Bundle SKUs?

Returns reduce both revenue and COGS, but only when the returned unit goes back into sellable inventory. A return that gets refurbished, donated, or trashed needs different treatment. Damages and shrinkage are inventory write-offs that flow through COGS as an adjustment.

Bundle SKUs are the most common COGS leak in Shopify accounting. Shopify's default behavior on a bundle is to deduct inventory from the bundle SKU, not the component SKUs. If the bundle SKU has no cost field set, COGS for that sale is zero. Bundle-heavy stores using apps like Shopify Bundles, Bold Bundles, or custom builds can understate COGS by 15-30%.

Here's the journal entry pattern for a bundle adjustment when components are tracked separately:

Bundle COGS true-up (period-end adjustment)
DRCost of Goods Sold$4,200
CRInventory Asset$4,200
Adjust May COGS for 700 bundles sold; component cost not captured by Shopify bundle SKU

For damaged and written-off inventory, the entry is similar but uses an inventory shrinkage subaccount so the loss is visible separately:

Inventory write-off
DRCOGS - Inventory Shrinkage$1,850
CRInventory Asset$1,850
Q2 cycle count variance and damaged units written off

You'll know this worked when every bundle sale, return, and damaged unit has a corresponding inventory and COGS movement. Your monthly inventory roll-forward should tie to the GL within $50.

6How Do You Apply the Cost of Goods Sold Formula and Reconcile?

With landed cost, expense classifications, and adjustments handled, the cost of goods sold formula itself is mechanical. Plug in the numbers and the result is COGS for the period. The harder work is reconciling that number against gross margin and inventory movement to make sure it's right.

Here's a worked example for a Shopify brand with $480,000 in May revenue:

May 2026 COGS calculation
Beginning inventory (May 1)$312,000
Plus: Purchases at landed cost$185,400
Less: Ending inventory (May 31)($338,200)
COGS before adjustments$159,200
Plus: Bundle component true-up$4,200
Plus: Shrinkage write-off$1,850
Less: COGS reversed on returns to stock($6,400)
Total May COGS$158,850

Gross margin on this brand is ($480,000 − $158,850) / $480,000 = 66.9%. That's roughly in line with what we see for typical DTC apparel and beauty brands in our book. If the number comes back at 85% or 40%, something is wrong upstream — usually unset cost fields, missing landed cost, or bundle leakage.

Stores using QuickBooks or Xero with Bookkeep for revenue recognition can automate the revenue and fee side of the entry. That leaves COGS as the manual piece tied to inventory movement. We use Bookkeep across the 100+ Shopify stores Ottit closes books for monthly because it cleanly separates merchant fees from product cost — the exact split this section is about. For payout reconciliation context, the Shopify Help Center guide to payouts explains how the gross-to-net flow lands in your bank.

You'll know this worked when COGS, gross margin, and inventory roll-forward all tie together. The gross margin should match what your team sees in operational dashboards like Triple Whale within 1-2 percentage points.

7Costing Method Comparison: FIFO vs. LIFO vs. Weighted Average

The cost of goods sold formula stays the same across all three methods. What changes is how each layer of inventory gets valued. The table below shows how the same purchase history produces different COGS and ending inventory numbers under each method.

How Each Costing Method Hits COGS

DimensionFIFOLIFOWeighted Average
Cost flow assumptionOldest units sell firstNewest units sell firstBlended cost across all units
COGS in rising-cost periodsLowerHigherMiddle
Ending inventory in rising-cost periodsHigherLowerMiddle
Tax impact in inflationHigher taxable incomeLower taxable incomeMiddle
GAAP allowed?YesYes (US only)Yes
IFRS allowed?YesNoYes
Best for Shopify DTC brandsMost common choiceRarely usedCommon with ERPs like Cin7
Audit complexityLowHighLow

Most Shopify brands Ottit closes books for use FIFO or weighted average. LIFO creates audit complexity and isn't allowed under IFRS, which matters if the brand ever raises from international investors or expands overseas.

8Common Mistakes in Applying the COGS Formula

  • Using supplier invoice cost instead of landed cost. Skipping freight, duty, and 3PL receiving fees understates COGS by 20-35% on imported goods.
  • Including Shopify Payments fees in COGS. Processing fees are merchant fees, not product cost. They belong in operating expenses or as a contra-revenue line.
  • Forgetting bundle component costs. If the bundle SKU's cost field is zero, Shopify reports zero COGS on bundle sales. The fix is a monthly true-up journal.
  • Mixing costing methods between periods. Switching from weighted average to FIFO mid-year breaks the formula and triggers tax filing complications. Pick one method and stick with it.
  • Not reversing COGS on returned-to-stock units. When a customer returns a sellable unit, both revenue and COGS need to reverse. Many stores reverse revenue but leave COGS, inflating cost and depressing margin.
  • Expensing inbound freight as a period cost. Inbound freight should be capitalized into inventory and released through COGS as units sell. Expensing it directly inflates current-period COGS and understates inventory on the balance sheet.

9Troubleshooting

Gross margin looks 10+ points off from expected

Start with the cost field on the variant. Pull a Shopify product export and filter for any SKU with cost = $0 or null. Bundle parents and recently launched products are the usual offenders. Update the cost field, then run a period-end true-up journal to correct historical COGS for any sales already booked at zero cost.

Inventory balance doesn't match the GL

This usually means purchases were booked at supplier invoice cost while inventory was valued at landed cost (or vice versa). Pull the inventory roll-forward — beginning balance, purchases received, COGS, ending balance — and compare each line to the GL. The variance almost always sits in freight or duty that was expensed instead of capitalized.

COGS spikes or drops unexpectedly month to month

Large month-over-month swings in COGS without a matching revenue swing usually point to a physical inventory adjustment (cycle count) hitting the books. Or it's a delayed landed cost capitalization from a PO received in a prior month. Check for journal entries posted to the inventory or COGS accounts that don't tie to a Shopify order or PO receipt.

10Frequently Asked Questions

Does the COGS formula change for service businesses?

Pure service businesses don't hold inventory, so they don't have COGS in the traditional sense. They report cost of services or cost of revenue instead, which captures direct labor and other costs of delivering the service. The formula above only applies to businesses that sell physical goods.

How do FIFO, LIFO, and weighted average affect the formula?

The formula stays the same. The costing method only changes how beginning inventory, ending inventory, and the cost layer of purchases are valued. FIFO uses oldest cost first, LIFO uses newest, and weighted average blends them. We cover this in detail in our Shopify inventory accounting methods guide.

Can a Shopify store use cash basis for COGS?

The IRS generally requires accrual accounting for inventory once a business crosses certain revenue thresholds. Cash basis COGS treats purchases as expenses when paid, which doesn't match the formula above. Stores in this situation typically work with their CPA to determine whether accrual is required for their specific facts.

Where does outbound shipping fit in the financials?

Outbound shipping (warehouse to customer) is a fulfillment expense, not COGS, in most DTC accounting setups. Some brands group it under a 'cost of sales' line below COGS to track true contribution margin. Either treatment is acceptable as long as it's consistent and disclosed.

How does the formula handle pre-orders and deposits?

Pre-order revenue isn't recognized until the product ships, so COGS isn't recognized either. The cash sits as deferred revenue and the inventory sits on the balance sheet until fulfillment. Our revenue recognition ASC 606 guide covers the timing rules in detail.

Should COGS be calculated per SKU or in aggregate?

Aggregate COGS is what hits the P&L. Per-SKU COGS is what drives merchandising decisions. Most Shopify brands calculate aggregate COGS in QuickBooks or Xero and use a separate tool — Triple Whale, Cin7, or a BI layer — for SKU-level margin analysis.

11Sources