Cost of Goods Sold & Inventory Ledger

Turn opening stock, purchase receipts and sales into a traceable inventory cost ledger for one interchangeable product. Compare FIFO with perpetual moving weighted-average costing on the same transaction sequence. See the cost assigned to each sale, the acquisition layers left in stock, and how the methods change gross profit while preserving total available cost. Open the period-end comparison to compare periodic weighted average with both ledger methods from the same inputs. Stock and value charts, transaction inspection and downloadable CSVs let you reconcile the calculations. This is a costing comparison, not an accounting-method election, tax return or compliance determination.

Inventory costing studio

Trace each sale back to its inventory cost

Compare FIFO and moving weighted-average costs, follow remaining stock, and reconcile every purchase to cost of goods sold or ending inventory.

One product. Two ways to assign its cost.

Use the same ordered receipts and sales to see how costing methods affect COGS, ending inventory and gross profit. The examples are illustrative. This comparison does not establish which method your business may use.

Example product: where the inventory stands

Units remaining
40 units
150 sold
Sales revenue
USD 3,060
Quantity sold × entered selling price
Cost available to assign
USD 2,250
Opening value plus receipt costs

Opening value USD 1,000 + receipt costs USD 1,250 = cost available USD 2,250. Each method assigns that same total between COGS and ending inventory.

Compare the cost assignment

FIFO

Cost of goods sold

USD 1,650

Green: cost released to sales. Bordered slate: cost remaining in stock.

Ending inventory
USD 600
Gross profit
USD 1,410
Gross margin
46.0784%

Moving weighted average

Cost of goods sold

USD 1,718.57

Green: cost released to sales. Bordered slate: cost remaining in stock.

Ending inventory
USD 531.43
Gross profit
USD 1,341.43
Gross margin
43.8375%

FIFO minus moving-average COGS: USD −68.57. The same sales revenue applies to both methods. Gross profit excludes selling costs, overhead and taxes; a larger modeled profit is not a recommendation to change accounting methods.

Display rounding can make visible subtotals differ slightly. Exact fractions are retained in the calculations and CSV; tiny nonzero values remain fractions.

Compare period-end weighted average

The period runs from opening inventory through the last transaction. The period average includes every receipt in that window. The moving average uses only the pool on hand when each sale happens.

Period average unit cost

USD 11.842105 / units

USD 2,250 ÷ 190 units available

Periodic minus moving-average COGS

USD 57.74

A positive amount raises period COGS and lowers ending inventory and gross profit by the same amount.

Split USD 2,250 of available cost

Solid green is cost assigned to sales. Bordered slate is cost left in stock.

  • FIFO

    USD 1,650 COGS · USD 600 in stock

  • Moving weighted average

    USD 1,718.57 COGS · USD 531.43 in stock

  • Periodic weighted average

    USD 1,776.32 COGS · USD 473.68 in stock

Period close amounts
Costing methodCOGSEnding inventoryGross profitGross margin
FIFOUSD 1,650USD 600USD 1,41046.0784%
Moving weighted averageUSD 1,718.57USD 531.43USD 1,341.4343.8375%
Periodic weighted averageUSD 1,776.32USD 473.68USD 1,283.6841.9505%

190 units available = 150 units sold + 40 units in stock. For every method, COGS plus ending value equals available cost at exact precision. FIFO assigns the same oldest layers as the transaction ledger.

Download period close CSV
Selectable period close CSV copy

Follow stock and value through the ledger

Each step shows the position after an event. Horizontal spacing means transaction order, not elapsed time. Quantity and inventory value use separate scales.

Inventory value · solid green FIFO, dashed slate moving average

Upper scale USD 1,650

Lower scale USD 0

OpeningEvent 4
Physical stock · units

Upper scale 150 units

Lower scale 0 units

OpeningEvent 4

Trace a transaction’s cost

Stock 150 → 30 units.

Sale revenue
USD 2,400
FIFO sale cost
USD 1,260
2 acquisition layer(s)
Moving-average sale cost
USD 1,320

Moving-average basis before this sale: USD 1,650 ÷ 150 units. The sale uses that average for 120 units.

FIFO layers consumed by orderA; costs in USD
Acquisition layerQuantity (units)Unit costReleased cost
Opening inventory100101,000
deliveryA2013260

What remains in inventory?

Moving-average unit cost: USD 13.285714 per units.

Remaining FIFO layers · USD
LayerQuantity (units)Unit costRemaining value
deliveryB4015600

Complete transaction ledger

After each transaction · quantity in units; money in USD
EventTypeStock afterReceipt costRevenueFIFO COGSMoving COGSFIFO ending valueMoving ending value
1. deliveryAreceipt1506500001,6501,650
2. orderAsale3002,4001,2601,320390330
3. deliveryBreceipt70600000990930
4. orderBsale400660390398.571429600531.428571

Export a ledger you can reconcile

Assumptions and limits
  • One interchangeable product and one quantity unit; no automatic unit or currency conversion.
  • Transactions follow the entered order. Later receipts cannot supply earlier sales.
  • Receipt value equals quantity times unit cost plus the acquisition cost assigned to that receipt.
  • FIFO releases the oldest available acquisition layers. Moving weighted-average cost uses remaining value divided by quantity immediately before each sale.
  • Exact rational costs are retained without internal cent rounding; displayed values may be rounded and tiny nonzero values may remain fractions.
  • Gross profit excludes selling costs and operating expenses. Zero revenue makes gross margin unavailable.
  • No returns, write-downs, shrinkage, manufacturing allocations, taxes, method elections or compliance determination.
  • CSV preserves exact fractions and formula-like values are prefixed with an apostrophe for spreadsheet safety.

CSV includes inputs, both costing methods, every sale’s FIFO allocations and the remaining layers. Exact fractions remain fractions. Formula-like values, including negatives, receive a protective apostrophe.

How to use this calculator

  1. Load Rising costs and freight or Falling purchase costs. Open Edit stock and transactions, name one product, and choose the same currency and quantity unit for every row.
  2. Enter opening quantity and its unit cost. For each receipt, enter received quantity, purchase unit cost and the additional acquisition cost assigned to that receipt. For each sale, enter sold quantity and selling price.
  3. Arrange receipts and sales in their actual sequence with Move up and Move down. Add, copy or remove rows as needed; a copy adds another transaction. Resolve stockouts at the affected sale before applying the ledger.
  4. Apply inventory ledger. Compare COGS, ending inventory and gross profit. Inspect the separate stock/value charts, select a transaction to trace FIFO allocations or its receipt cost, and review remaining acquisition layers.
  5. Open Compare period-end weighted average to see how all receipts affect closing COGS and inventory. Download the period close CSV or the complete inventory ledger CSV for reconciliation.

The Formula

The mathematical logic powering this calculation is:

Opening inventory value = opening quantity × opening unit cost. One opening cost layer is used; zero opening quantity contributes zero value even when a unit cost is entered. All transactions must concern one interchangeable product and use one quantity unit and currency. Labels do not convert units or currencies.
Receipt cost = received quantity × purchase unit cost + additional acquisition cost assigned to that receipt. FIFO creates a new acquisition layer with unit cost = receipt cost / received quantity. The moving-average pool adds the receipt’s complete quantity and cost to the remaining pool. You choose which costs belong in the acquisition charge; the calculator does not classify freight, taxes or other expenses for your accounting situation.
Transactions are processed in the order entered. Every sale must have enough stock immediately before that row. Later receipts cannot cover an earlier stockout. A stockout invalidates the ledger with an error at that sale’s quantity; no partial result is presented as a completed ledger. Copying creates a real additional transaction, and moving rows can change costs or stock availability.
For each sale, FIFO releases units from the oldest available layer until the sold quantity is covered. Each allocation records its source layer, quantity, unit cost and released cost. FIFO COGS is the sum of those released costs. The remaining quantity in each layer retains that layer’s unit cost.
Moving weighted-average unit cost before a sale = remaining pool value / remaining pool quantity. Sale COGS = sold quantity × that unit cost. Subtract the sold quantity and that exact cost from the pool. The average changes when a receipt enters the pool; a sale alone does not change it. This is a perpetual moving average, not a periodic average that includes later purchases. After complete stock depletion, both quantity and value are exactly zero; unit cost is unavailable until another receipt arrives.
Periodic weighted-average unit cost = (opening value + all receipt costs) ÷ (opening quantity + all received quantity). The period runs from opening stock through the last entered transaction. Ending inventory = remaining quantity × period average unit cost. Period COGS = available cost − ending inventory. With no available units, the average is unavailable and both assigned costs are zero. The period calculation yields aggregate costs. Earlier sales still require stock. FIFO shows the same final allocation because the same oldest units are sold in this ledger.
Sale revenue = quantity sold × entered selling price. Gross profit = revenue − COGS. Gross margin = gross profit / revenue × 100, unavailable when revenue is zero. Zero-price sales and negative gross profit or margins are retained. Selling expenses, general overhead and taxes are excluded; gross profit is not net profit or cash flow.
For each method, opening value + receipt costs = COGS + ending value. Opening quantity + receipts = sold quantity + closing quantity. All methods use identical quantities and revenue. The transaction comparison is FIFO COGS − moving-average COGS. A positive transaction difference means FIFO assigns more cost to sales. In the period comparison, the signed difference is periodic COGS − moving-average COGS.
Exact rational arithmetic preserves all quantities, unit costs, allocations and totals without internal cent rounding. Display values round half away from zero for readability; tiny nonzero values remain exact fractions when rounding would hide them. The charts and tables use the same model results. Transaction spacing on charts represents event order, not elapsed time. The inventory ledger CSV retains canonical fractions, inputs, both transaction methods, every allocation and remaining layers. The separate period close CSV records the exact cost and quantity reconciliation for all three methods. Formula-like values, including negative amounts, have an apostrophe prefix for spreadsheet safety.
Input limits: 0–120 receipt or sale rows. Opening quantity is 0–1,000,000,000 and each transaction quantity is greater than zero through 1,000,000,000, with at most six decimals. Opening and purchase unit costs and sale prices are 0–1,000,000,000 with at most six decimals. Additional acquisition cost is 0–1,000,000,000,000 per receipt with at most two decimals. Required blanks, malformed decimals, commas, exponents, negative values and overprecision are rejected. IDs are unique, letter-led ASCII strings of 1–40 characters; labels and product names have 1–100 characters, the quantity-unit label 1–24, and the currency label 1–12. Text labels cannot contain control codes or surrounding spaces.
This model excludes LIFO, specific identification, returns, shrinkage, write-downs, manufacturing cost allocations, multiple-product pools, rebates and currency conversion. It does not determine tax treatment, reporting requirements or whether changing a costing method is permitted. Inventory standards include requirements beyond these cost formulas, including valuation considerations not modeled here.
The IFRS Foundation’s IAS 2 materials describe FIFO and weighted-average cost assignment; the 2021 issued text in paragraph 27 describes averaging for a whole period or as receipts arrive. IRS Publication 334 describes the relationship among available cost, closing inventory, COGS and gross profit. These are method references, not a claim that this simplified ledger establishes IFRS compliance or produces a tax-filing result. Sources were reviewed on November 18, 2026.

Worked Example

If you input:

  • Opening stock: 100 units at USD 10 each: USD 1,000.
  • Receipt A: 50 units at USD 12 plus USD 50 acquisition cost: USD 650, or USD 13 per received unit.
  • Sale A: 120 units at USD 20: revenue USD 2,400.
  • Receipt B and sale B: Receive 40 units at USD 15 with no additional charge, then sell 30 units at USD 22: revenue USD 660.

Result:

Total available cost is USD 2,250 and revenue is USD 3,060. FIFO assigns 100 × 10 + 20 × 13 = USD 1,260 to sale A, then 30 × 13 = USD 390 to sale B. FIFO COGS is USD 1,650; the remaining 40 units are valued at USD 600, and gross profit is USD 1,410. Moving average starts sale A at USD 11 per unit, assigning USD 1,320 and retaining USD 330. Receipt B brings the remaining pool to 70 units costing USD 930. Sale B costs 30 × 930/70 = USD 2,790/7. Total moving-average COGS is USD 12,030/7 (about USD 1,718.57), ending value USD 3,720/7 (about USD 531.43) and gross profit USD 9,390/7 (about USD 1,341.43). FIFO minus moving-average COGS is −480/7, about USD −68.57. Both methods reconcile exactly to USD 2,250 before display rounding. Periodic weighted average includes all 190 available units at USD 225/19 each. Closing inventory is USD 9,000/19 (about USD 473.68), COGS is USD 33,750/19 (about USD 1,776.32) and gross profit is USD 24,390/19 (about USD 1,283.68).

Frequently Asked Questions

What does this cost of goods sold calculator add beyond beginning stock plus purchases minus ending stock?

FIFO allocations show the acquisition layers consumed. Moving average tracks the remaining pool’s cost as receipts and sales occur. The period-end panel adds a single average for all opening stock and receipts. All three reconcile to the available-cost equation.

Is moving average the same as a period-end weighted average?

Moving average uses the stock and cost on hand immediately before each sale. The period-end average pools all opening stock and purchases in the entered period, including purchases after earlier sales. Later price changes can therefore move COGS, ending inventory and gross profit.

Why does changing transaction order change the result?

Receipts change the quantity and cost available for subsequent sales. Moving a receipt after a sale can change the average cost used by that sale or create a stockout. Labels are not dates, and the tool never sorts rows automatically.

Can I include freight or other acquisition charges?

Each receipt accepts an additional acquisition cost allocated across that receipt’s units. Enter only costs appropriate to your records and reporting method. The calculator does not decide whether a charge is capitalizable, deductible or a selling expense.

What happens if I sell more units than are available?

The ledger becomes invalid and identifies the affected sale quantity. Add or move the relevant receipt before the sale, or correct the quantity. The model does not use future stock, create negative inventory or silently reduce a sale.

Why are some exported values fractions?

Partial allocations and moving averages can produce repeating decimals. Exact fractions prevent cumulative rounding from breaking cost reconciliation. The interface rounds for readability, while tiny nonzero amounts remain fractions and the CSV preserves exact values.

Can I compare multiple products or record returns?

Use a separate ledger for each interchangeable product and quantity unit. Returns, shrinkage, write-downs, manufacturing allocations and multi-product pools are outside this model. Do not represent those events by inventing negative receipts or sales.

Does the method with higher gross profit give the correct accounting answer?

A higher gross profit follows from assigning less cost to sales in the entered period. Accounting-method eligibility and changes require separate assessment. Gross profit excludes selling costs, overhead and taxes.

Similar Calculators