SUMIFS for stock in and stock out, with one example

· 6 min read

A stock sheet that records every delivery and every sale as its own row needs one formula to turn that list into a number per product. That formula is SUMIFS. It looks long, but it only ever does one thing: add up a column, skipping the rows you did not ask for.

This guide walks through it on eight rows of example data, so you can check each number by eye. It uses the two-tab layout from how to track inventory in Google Sheets. If your sheet has different columns, only the letters change.

How SUMIFS reads

Google's SUMIFS reference gives the pattern as:

SUMIFS(sum_range, criteria_range1, criterion1, [criteria_range2, criterion2, ...])

In plain words:

  • sum_range is the column of numbers to add up.
  • criteria_range1 is a column to look in, and criterion1 is what to look for there.
  • After that you can add more pairs of column and condition.

A row is counted only when it passes every condition. Pass one and fail another, and the row is left out.

The example data

The Stock moves tab has one row per movement. Date is column A, SKU is B, Type is C and Quantity is D.

Row Date SKU Type Quantity
2 2026-11-02 M-101 In 24
3 2026-11-03 M-101 Out 6
4 2026-11-04 M-102 Out 4
5 2026-11-05 P-201 In 30
6 2026-11-06 M-101 Out 10
7 2026-11-09 M-102 In 12
8 2026-11-10 P-201 Out 8
9 2026-11-12 M-101 Out 5

The Products tab has one row per product, with SKU in column A and Opening stock in column F. M-101 is the blue mug (opening stock 40), M-102 the red mug (25) and P-201 the dinner plate (20).

The stock in and stock out formulas

On the Products tab, add three columns.

  1. Stock in (H2):

    =SUMIFS('Stock moves'!D:D, 'Stock moves'!B:B, A2, 'Stock moves'!C:C, "In")

  2. Stock out (I2):

    =SUMIFS('Stock moves'!D:D, 'Stock moves'!B:B, A2, 'Stock moves'!C:C, "Out")

  3. Stock left (J2):

    =F2+H2-I2

Fill all three down. Now trace the first formula for the blue mug, where A2 holds M-101.

  • The first condition keeps rows where column B is M-101. That is rows 2, 3, 6 and 9.
  • The second condition keeps rows where column C is In. Of those four, only row 2 passes.
  • The quantity in row 2 is 24. Stock in is 24.

Stock out keeps the same four rows and then asks for Out. Rows 3, 6 and 9 pass: 6 + 10 + 5 = 21. Stock left is 40 + 24 − 21 = 43.

All three products come out like this:

SKU Opening stock Stock in Stock out Stock left
M-101 40 24 21 43
M-102 25 12 4 33
P-201 20 30 8 42

Three details in the formula that matter

A2, not "M-101". The SKU condition points at a cell. When you fill the formula down, A2 becomes A3 and A4, so each row adds up its own product. Type "M-101" into the formula and every row would show the blue mug's total.

Quotation marks around In and Out. Text typed into a formula has to be in quotation marks. A cell reference such as A2 does not.

All three ranges are the same size. Each one is a whole column (D:D, B:B, C:C), so they always line up and new rows are picked up without touching the formula. If you use fixed ranges instead, such as D2:D500, give every range the same start and end row. In Excel, Microsoft's SUMIFS page says ranges of different sizes return a #VALUE! error.

Add a third condition for dates

More pairs narrow the sum further. To count only blue mugs that went out on or after 5 November:

=SUMIFS('Stock moves'!D:D, 'Stock moves'!B:B, A2, 'Stock moves'!C:C, "Out", 'Stock moves'!A:A, ">="&DATE(2026,11,5))

The date condition is built from two pieces joined with &: the comparison in quotation marks, then the date. Row 3 is dated 3 November, so it drops out. Rows 6 and 9 stay: 10 + 5 = 15.

In place of DATE(2026,11,5) you can point at a cell that holds a date, for example ">="&$M$1, and change the date without editing the formula. The same pattern with TODAY()-30 gives sales in the last 30 days, which is the starting point for setting a reorder level.

Date conditions only work when the Date column holds real dates. A date typed as text will not pass a comparison.

When SUMIFS gives 0 or the wrong number

SUMIFS never shows an error for a row it could not match. It leaves the row out, and the total is quietly too small. These are the usual reasons.

  • A space at the end of a SKU. "M-101 " with a trailing space is not the same text as "M-101", so the row matches no product. A dropdown on the SKU column prevents this. Google's page on dropdown lists shows how to add one.

  • A type that is not exactly In or Out. "Stock in", "IN " or "Sold" will pass neither formula. Use a dropdown here too.

  • A quantity stored as text. A number typed with a letter or a stray apostrophe ("6 pcs") is text, and text is not added up. This counts the entries in the Quantity column that are not numbers:

    =COUNTA('Stock moves'!D2:D)-COUNT('Stock moves'!D2:D)

    It should be 0.

One check catches the first two problems together. Every quantity in Stock moves should land in exactly one product's Stock in or Stock out. So this formula, in any spare cell on the Products tab, should give 0:

=SUM('Stock moves'!D:D)-SUM(H2:H200)-SUM(I2:I200)

With the example data, all quantities add up to 99. Stock in across the three products is 24 + 12 + 30 = 66 and stock out is 21 + 4 + 8 = 33. 99 − 66 − 33 = 0. If someone adds a row for SKU "M-103" before that product exists on the Products tab, with a quantity of 7, the check shows 7 and you know there is a row to find.

SUMIF and SUMIFS are not the same order

SUMIF is the older function for a single condition. The trap is that the column to add up moves.

Function Pattern Where the sum column goes
SUMIF SUMIF(range, criterion, [sum_range]) Last
SUMIFS SUMIFS(sum_range, criteria_range1, criterion1, ...) First

Total units out across every product, written both ways:

=SUMIF('Stock moves'!C:C, "Out", 'Stock moves'!D:D)

=SUMIFS('Stock moves'!D:D, 'Stock moves'!C:C, "Out")

Both give 33. If a SUMIFS returns 0 right after you turned it from a SUMIF, check that the Quantity column is now the first argument.

The same formulas in a ready-made layout

Everything above works in a plain spreadsheet. The BoltSheets inventory tracker template uses these two SUMIFS formulas for its Stock in and Stock out columns. In the demo you can say "sold 3 blue mugs" and it previews a new row for Stock moves, which a person has to confirm. The formula columns are never written to, so stock left changes only because the formulas recalculate. BoltSheets is in early access and works with Google Sheets only.

Once stock in and stock out are right, the same columns feed stock value and every other number the sheet reports.

Common questions

Does SUMIFS work the same way in Excel?

Yes. The arguments come in the same order, sum range first and then pairs of range and condition, so the formulas in this guide can be typed into Excel unchanged. Microsoft's page says Excel accepts up to 127 pairs and returns a #VALUE! error if the ranges are different sizes.

Why does my SUMIFS return 0?

No row passed every condition. The usual causes are a SKU or type that is typed differently on the two tabs, often with a space at the end, or dates stored as text. Take the conditions out one at a time until a number appears, and the last one you removed is the one to fix.

Can SUMIFS match one value or another, such as In or Return?

Not in one formula. Every condition has to be true for the same row, so asking for a type of In and a type of Return matches nothing. Write one SUMIFS for each value and add the two together with a plus sign.

Can I use SUMIFS with only one condition?

Yes. SUMIFS with a single range and condition gives the same result as SUMIF. Many people use SUMIFS every time so that the sum range is always the first argument and a second condition can be added later without rearranging the formula.