COVARIANCE.S function
Returns the sample covariance of two data sets (dividing by n − 1), used when your data are a sample from a larger population.
Available in Excel 2010 and later, Microsoft 365, Excel for the web, Excel for Mac 2011 and later
Excel 2010 and laterWorks in Google Sheets
Syntax
COVARIANCE.S(array1, array2)| Argument | What it means | |
|---|---|---|
array1 | Required | The first range of numbers. |
array2 | Required | The second range, with the same number of values. |
Returns: A number: positive if the variables tend to move together, negative if they move in opposite directions.
How COVARIANCE.S works
COVARIANCE.S measures how two variables move together, exactly like COVARIANCE.P, except that it divides the sum of products by n − 1 instead of n. That small change corrects the tendency of a sample to understate the spread of the population it came from, the same reason STDEV.S divides by n − 1.
Use the .S version when your rows are a sample: six months out of many years of trading, 40 customers out of thousands. Use .P only when you truly have every member of the group. For small samples the difference is noticeable (here n/(n−1) = 6/5, so the sample result is 20% larger); for large samples it disappears.
Examples
1Sample covariance of stock returns
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Month | Stock A % | Stock B % | ||
| 2 | Jan | 2.1 | 1.5 | 3.2473 | |
| 3 | Feb | -1.3 | -2 | ||
| 4 | Mar | 3.4 | 2.8 | ||
| 5 | Apr | 0.8 | 1.1 | ||
| 6 | May | -0.5 | -1.2 | ||
| 7 | Jun | 1.9 | 2.2 |
Result: 3.2473
Six months are only a sample of the stocks' history, so the sample covariance 3.2473 is the better estimate (formatted to 4 decimal places). It equals the population figure 2.7061 × 6/5.
2Advertising spend and sales
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Month | Ad spend (k€) | Sales (k€) | ||
| 2 | Jan | 2 | 41 | 11.4000 | |
| 3 | Feb | 3.5 | 58 | ||
| 4 | Mar | 1.5 | 44 | ||
| 5 | Apr | 4 | 56 | ||
| 6 | May | 3 | 53 | ||
| 7 | Jun | 5 | 66 |
Result: 11.4000
The covariance is 11.4000 (k€ × k€). Dividing it by the variance of ad spend gives the slope of the best-fit line, about 6.84 k€ of sales per extra 1 k€ of advertising, the same as =SLOPE(C2:C7, B2:B7).
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#N/A | The ranges contain different numbers of values. | Use ranges of equal size. |
#DIV/0! | There are fewer than two pairs of values. | Covariance needs at least two observations. |
Tips
- Covariance depends on units: measuring sales in euros instead of thousands multiplies it by 1,000. Use CORREL when you need a unit-free measure.
Google Sheets
COVARIANCE.S also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.
COVARIANCE.S in other languages
In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.
| Language | Function name |
|---|---|
| Danish | KOVARIANS.S |
| Dutch | COVARIANTIE.S |
| Finnish | KOVARIANSSI.S |
| French | COVARIANCE.STANDARD |
| German | KOVARIANZ.S |
| Hungarian | KOVARIANCIA.M |
| Italian | COVARIANZA.C |
| Norwegian (Bokmål) | KOVARIANS.S |
| Polish | KOWARIANCJA.PRÓBKI |
| Portuguese (Brazil) | COVARIAÇÃO.S |
| Portuguese (Portugal) | COVARIÂNCIA.S |
| Russian | КОВАРИАЦИЯ.В |
| Spanish | COVARIANZA.M |
| Swedish | KOVARIANS.S |
| Turkish | KOVARYANS.S |