The cost of goods sold formula is simple at company level, but for a single item bought at changing prices the answer depends on the valuation method. Enter opening stock and the item's purchases and sales in order, and the calculator works out cost of goods sold and ending inventory under first in, first out (FIFO) and weighted average side by side, with the profit gap between them. Both methods are accepted in the financial statements of companies in Saudi Arabia; LIFO is not. For the whole business, the COGS formula tab works from opening and closing balances and purchases.
How to calculate cost of goods sold under both methods
Under FIFO the oldest units are treated as sold first, so each sale is costed from the oldest purchase layer still in stock and the newest units remain at the end. Under moving weighted average, the unit cost is recalculated after every purchase (stock value ÷ stock quantity) and each sale is costed at that average. Periodic weighted average works out one average at the end of the period from everything that was available for sale.
COGS = Opening + Purchases − Ending · WAC = Stock value ÷ Stock quantity
FIFO: COGS SAR 3,850.00, ending inventory SAR 1,050.00 (70 units at 15), gross profit SAR 3,110.00.
Moving weighted average: COGS SAR 4,004.00, ending inventory SAR 896.00, gross profit SAR 2,956.00.
Periodic weighted average: COGS SAR 4,042.50, ending inventory SAR 857.50. Load it with the "Example: rising purchase prices" button.
The cost of goods sold formula for a whole period
If you do not track every movement but you do count stock at the start and end of the period, cost of goods sold is what was available for sale less what is left: opening inventory, plus purchases and freight-in, less purchase returns, less closing inventory. This is the periodic system, and closing inventory is the physical count valued under one of the two methods.
Why FIFO and weighted average give different results
When purchase prices rise, FIFO gives lower cost, higher profit and an ending inventory closer to market price, because what remains is what you bought last. When prices fall, the effect reverses. Weighted average lands between the two and smooths out price swings. The gap is not a real gain or loss: cost plus ending inventory is the same under both methods, and only the timing of cost in the income statement changes.
Ending inventory sits on the balance sheet and feeds into the zakat base, so the valuation method moves both figures. Pick one method, keep it from year to year, and disclose any change in the financial statements.
Why LIFO is not offered here
Last in, first out (LIFO) is not permitted under IAS 2 Inventories, and IFRS is the framework endorsed in the Kingdom. IAS 2 allows FIFO and weighted average, and specific identification for items that are not interchangeable, such as property or vehicles tracked by serial number. Finance staff used to US GAAP, where LIFO is still permitted, need to drop it when preparing accounts for a Saudi entity.
Download the item's movements in Excel
The "Download Excel with movements" button gives you two sheets. The moving average sheet is built with formulas, each row taking its cost and balance from the row above, so changing a quantity or price updates the whole table, with a cell for the periodic average. The FIFO sheet lists the layers used by each sale. The comparison and both movement tables also download as a PDF.
Common mistakes in inventory valuation
- Costing every unit sold at the latest purchase price.
- Leaving freight on purchases out of inventory cost.
- Entering movements out of date order, which changes the average and the FIFO layers.
- Carrying closing stock at cost when its net realisable value is lower; IAS 2 requires the lower of the two.
- Switching method between years without disclosure.
What to do after the result
Compare cost of goods sold here with your books for the same item; a large gap points to a missing movement or a wrong price. If what you need is the value of stock at the closing date, take the ending inventory figure under your company's method and test it against net realisable value before you book it. Download the Excel file to carry on with the rest of the month, or keep the PDF with the stock count file.
When you carry hundreds of items, not one
The calculator walks through one item. In a store or warehouse with hundreds of items, every purchase invoice shifts an average or adds a layer, every sale, return and transfer moves the balance, and manual costing falls behind. At Microtec we offer anyone running a store or warehouse in the Kingdom accounting software (ERP) with purchasing, inventory, sales and finance together. Load your fastest-moving items into the trial and watch their cost for a month.