Excel guide · 5 min read
How to calculate a z-score in Excel
=(B2-AVERAGE($B$2:$B$13))/STDEV.S($B$2:$B$13) and fill down. The result is how many standard deviations each value sits above (positive) or below (negative) the average. Excel's =STANDARDIZE(B2,AVERAGE($B$2:$B$13),STDEV.S($B$2:$B$13)) gives the same number.Sample data
Every result on this page was calculated from this sheet by the same spreadsheet engine the Cellwise app uses.
| A | B | |
|---|---|---|
| 1 | Day | Orders |
| 2 | Mon 2 Nov | 142 |
| 3 | Tue 3 Nov | 138 |
| 4 | Wed 4 Nov | 151 |
| 5 | Thu 5 Nov | 147 |
| 6 | Fri 6 Nov | 139 |
| 7 | Sat 7 Nov | 288 |
| 8 | Sun 8 Nov | 145 |
| 9 | Mon 9 Nov | 150 |
| 10 | Tue 10 Nov | 136 |
| 11 | Wed 11 Nov | 149 |
| 12 | Thu 12 Nov | 61 |
| 13 | Fri 13 Nov | 144 |
Download this sheet as an Excel practice file (.xlsx)
The z-score formula
An online shop wants to know which days were unusual over two weeks. A z-score answers that on a common scale: 0 is an average day, 1 is one standard deviation above, -2 is two below.
The dollar signs matter. Without them, filling down shifts the range to B3:B14, B4:B15 and so on, and each row is compared with a different, shrinking set of days. Lock the range, leave the B2 at the front relative.
Result: 2.7739612722
About 2.77: Saturday's promo day (288 orders) sits about 2.7 standard deviations above the two-week average.
STANDARDIZE: the same thing, spelled out
STANDARDIZE(x, mean, standard_dev) does the subtraction and division for you, but it does not calculate the mean or standard deviation. You still pass them in: =STANDARDIZE(B2,AVERAGE($B$2:$B$13),STDEV.S($B$2:$B$13)). A common mistake is =STANDARDIZE(B2,$B$2:$B$13,...), passing the range where the mean should go.
There is no advantage in accuracy. Use STANDARDIZE if it makes the sheet easier to read, or the plain formula if colleagues will audit it. A cleaner layout for both: put the mean in E2 and the standard deviation in E3 once, then use =(B2-$E$2)/$E$3. If the standard deviation is 0 (every value identical), STANDARDIZE returns #NUM! and the plain formula returns #DIV/0!.
Sample or population standard deviation?
Use STDEV.S when the data is a sample of a bigger process, such as two weeks out of the shop's whole history. Use STDEV.P when it is the complete group, such as the final scores of every student in one class when the class is all you are describing. Textbook z-score formulas for test scores often use the population version.
STDEV.P is smaller, so z-scores based on it are slightly larger. With 12 values the difference is about 4%, which can tip a borderline value over a cutoff. The formula below uses the population standard deviation written out; in Excel you would just swap STDEV.S for STDEV.P.
Result: 2.8973080559
About 2.90 for the promo day with the population standard deviation, compared with 2.77 using STDEV.S.
Flag outliers with |z| > 2 or 3
Wrap the z-score in ABS so high and low values are both caught, and use IF to label them. The usual rule of thumb is |z| > 2 for "worth a look" and |z| > 3 for "very unusual". These come from the normal (bell) curve, where roughly 95% of values fall within 2 standard deviations, so they only mean much when the data is roughly bell-shaped.
To count the flags in one cell: =SUMPRODUCT(--(ABS(($B$2:$B$13-AVERAGE($B$2:$B$13))/STDEV.S($B$2:$B$13))>2)). Here that returns 1: only the promo day. The outage day, Thursday 12 Nov with 61 orders, scores about -1.76 and is not flagged. The next section explains why.
Result: Check
Check: the promo day's z-score of about 2.77 is past the 2 line. Filled down, this is the only row flagged.
Why |z| > 3 can miss the outliers in small data
Outliers inflate the standard deviation they are measured against. Take out the promo and outage days and the other ten days have a standard deviation of about 5.3 orders. With them in, it is about 50. So the outage day scores only -1.76 and slips under the |z| > 2 rule, even though it was 75 orders below the slowest normal day.
There is also a hard limit. With the sample standard deviation, no value in a set of n numbers can have a z-score bigger than (n - 1) / SQRT(n). For 12 days that is about 3.18, and for 10 values or fewer it is under 3, so a |z| > 3 rule can never fire at all. For small data, or data with several odd values, compare against the median instead. A common robust version is the modified z-score: 0.6745 x (value - median) / MAD, where MAD is the median of the absolute distances from the median, with values beyond 3.5 or -3.5 flagged.
Result: -10.240136364
About -10.24: measured against the median (144.5) and a MAD of 5.5 orders, the outage day is far past the -3.5 line, not borderline. The promo day scores about 17.6, and a normal day such as Wed 4 Nov about 0.8. The MEDIAN(ABS(...)) part needs Ctrl+Shift+Enter in Excel 2019 and earlier.
Highlight unusual values without a helper column
Conditional formatting can colour the cells directly with the same test, so the flags update as you add days.
- Select B2:B13.
- Go to Home > Conditional Formatting > New Rule and choose Use a formula to determine which cells to format.
- Enter
=ABS((B2-AVERAGE($B$2:$B$13))/STDEV.S($B$2:$B$13))>2and pick a fill colour. - Click OK. The rule is written for B2, the top-left cell of the selection, and Excel adjusts it for every other cell.
Common mistakes
Forgetting the $ signs
Lock the range with $B$2:$B$13 (press F4 after selecting it) so every row compares against the same mean and standard deviation.
Passing the range as the mean in STANDARDIZE
STANDARDIZE needs the mean and standard deviation as numbers: STANDARDIZE(B2,AVERAGE(range),STDEV.S(range)).
Trusting |z| > 3 on a dozen values
With 10 or fewer values it can never trigger, and big outliers hide each other. Use |z| > 2 as a prompt to look, or the median-based modified z-score.
Reading z-scores as percentiles
A z of 2 does not mean "top 2%". Converting z to a percentile with NORM.S.DIST(z,TRUE) only holds if the data is close to normal.
FAQ
What is the formula for z-score in Excel?
=(x-AVERAGE(range))/STDEV.S(range), with the range locked using $ signs. STANDARDIZE(x,AVERAGE(range),STDEV.S(range)) is the built-in equivalent.
Should I use STDEV.S or STDEV.P for a z-score?
STDEV.S if your data is a sample of something larger, STDEV.P if it is the entire group you are describing. Use the same one for every row and say which you used.
What z-score counts as an outlier?
Common cutoffs are beyond 2 or -2 for possible outliers and beyond 3 or -3 for strong ones. They assume roughly bell-shaped data and enough values; on small samples, check the median-based method too.
How do I convert a z-score to a percentile in Excel?
=NORM.S.DIST(z,TRUE) returns the share of a normal distribution below that z-score. It is only meaningful if your data is roughly normal. For the real position of a value in your data, use PERCENTRANK.INC instead.
Functions used
AVERAGEMean of numbersSTDEV.SStandard deviationABSAbsolute valueIFPicks a result from a testMEDIANMiddle valueSUMPRODUCTMultiply then addSQRTSquare rootCOUNTCounts numbers
Related guides
- How to calculate standard deviation in Excel
- How to find the median in Excel
- How to calculate variance in Excel
- How to calculate percentiles and quartiles in Excel
- How to calculate percent difference in Excel
- How to calculate profit margin in Excel
Updated