# How to calculate standard deviation with criteria in Excel

Filter the values, then take the standard deviation: `=STDEV.S(FILTER(C2:C9,B2:B9=F1))`.

**Excel:** `=STDEV.S(FILTER(C2:C9,B2:B9=F1))` (Excel 2021, 2024 and Microsoft 365)

**Google Sheets:** the same formula works.

## Example

Sample data (row 1 is the header):

| A | B | C | D | E | F |
| --- | --- | --- | --- | --- | --- |
| Batch | Machine | Fill weight (g) |  | Machine | M2 |
| B-01 | M1 | 501.2 |  | Std deviation |  |
| B-02 | M2 | 498.4 |  |  |  |
| B-03 | M1 | 500.6 |  |  |  |
| B-04 | M2 | 503.9 |  |  |  |
| B-05 | M2 | 496.8 |  |  |  |
| B-06 | M1 | 499.7 |  |  |  |
| B-07 | M2 | 501.5 |  |  |  |
| B-08 | M1 | 500.9 |  |  |  |

Formula in F2: `=STDEV.S(FILTER(C2:C9,B2:B9=F1))`

Result: 3.17

## How it works

There is no STDEVIFS. FILTER keeps the four M2 weights and STDEV.S measures their spread: about 3.17 g, much wider than machine M1, which points to the machine that needs adjusting.

## Other ways

- `=STDEV.S(IF(B2:B9=F1,C2:C9))`: For Excel 2019 and older, entered with Ctrl+Shift+Enter. IF returns FALSE for other machines, which STDEV.S ignores.

## Common mistakes

- If only one row matches, STDEV.S returns #DIV/0!.
- In the IF version, a third argument of 0 adds zeros for the other machines and wrecks the result.

## Questions

**How do I use two conditions?**

Multiply the tests: `=STDEV.S(FILTER(C2:C9,(B2:B9=F1)*(C2:C9>490)))`.

**Does this work in Google Sheets?**

Yes. Google Sheets has FILTER and STDEV.S.

Every formula and result on this page was checked by running it in the Spreadsheet Practice formula engine on 2026-10-30.

Source: https://spreadsheetpractice.com/formulas/standard-deviation-with-criteria
