To calculate sample covariance in Google Sheets, use the COVARIANCE.S function: type =COVARIANCE.S(data_range_Y, data_range_X) and press Enter. It returns the sample covariance between two data sets, which tells you whether they move together and in which direction. You need two columns of paired numeric data with the same number of values, and no text or blank cells inside the ranges.
What You'll Need
- A Google account and access to Google Sheets (desktop browser or the mobile app).
- Two columns (or rows) of numeric data that are paired — each value in one range must correspond to a value in the other range.
- The two ranges must be the same size and contain only numbers (no text, no empty cells).
Step-by-Step
- Open your spreadsheet. Go to Google Sheets and open the file with your data, or create a new blank spreadsheet.
- Arrange your data in two columns. Put one variable in column A and the other in column B, starting from the same row. For example, A2:A11 and B2:B11. Each row should represent one observation pair.
- Click an empty cell where you want the covariance result to appear.
- Type the formula. Enter
=COVARIANCE.S(then select the first range (for example, A2:A11), type a comma, select the second range (B2:B11), and close the parenthesis. The formula looks like=COVARIANCE.S(A2:A11, B2:B11). The order of the ranges does not change the result. - Press Enter. The cell shows the sample covariance. A positive value means the two variables tend to move in the same direction; a negative value means they tend to move in opposite directions; near zero suggests little linear relationship.
- Check the result against the data size. COVARIANCE.S divides by (n−1), where n is the number of pairs. If you need population covariance (dividing by n), use
COVARIANCE.Pinstead. - Format the number if needed. Select the result cell and use Format > Number to show more decimal places or a specific format.
Common Mistakes
- Mismatched range sizes. COVARIANCE.S requires both ranges to have the same number of cells. If one range is A2:A11 and the other is B2:B12, you get an error.
- Including text or blanks. The function ignores text and empty cells, but that can silently shift your pairs. Make sure both ranges contain only numbers and no gaps.
- Using the wrong function. COVARIANCE.S is for a sample; COVARIANCE.P is for a population. Using the wrong one gives a slightly different number.
- Forgetting that covariance is not correlation. Covariance depends on the units of your data, so a large covariance does not necessarily mean a strong relationship. Use CORREL for a standardized measure.
- Selecting entire columns with headers. If your range includes a text header, the function may return an error or ignore that cell and misalign the pairs.
Tips
- Label your columns clearly so you can verify which range is which when writing the formula.
- Use named ranges (Data > Named ranges) to make formulas easier to read and less error-prone.
- To see the relationship more intuitively, calculate correlation with
=CORREL(range1, range2); it is scaled between -1 and 1. - If you add new rows later, update the range in the formula or use an open-ended range like A2:A if you are sure no text follows.
- Remember that labels can differ slightly by version, device, or region — the function name itself is consistent.
Troubleshooting
- #N/A error: The two ranges have different sizes. Check that both contain the same number of cells.
- #VALUE! error: One or both ranges contain text that cannot be interpreted as a number. Remove text or adjust the range.
- #DIV/0! error: Fewer than two paired numeric values. You need at least two pairs for sample covariance.
- Result seems wrong: Verify that each row pairs the correct values. Sorting one column without the other breaks the pairing.
- Formula not calculating: Check that the cell is not formatted as text. Use Format > Number > Automatic.
Frequently Asked Questions
What is the difference between COVARIANCE.S and COVARIANCE.P?
COVARIANCE.S calculates sample covariance (divides by n−1), used when your data is a sample of a larger population. COVARIANCE.P calculates population covariance (divides by n), used when your data is the entire population.
Can I use COVARIANCE.S with non-numeric data?
No. Both ranges must contain numeric values. Text and empty cells are ignored, which can misalign pairs, so clean your data first.
Does the order of the ranges matter?
No. COVARIANCE.S(A1:A10, B1:B10) gives the same result as COVARIANCE.S(B1:B10, A1:A10).
How many data pairs do I need?
At least two pairs. With fewer, you get a #DIV/0! error because the denominator (n−1) becomes zero.
Can I calculate covariance for more than two variables at once?
No, COVARIANCE.S takes exactly two ranges. For multiple variables, create a covariance matrix using multiple formulas or the CORREL function for each pair.
Why is my covariance so large?
Covariance is not standardized; it depends on the scale of your data. A large value may simply reflect large units. Use CORREL to get a standardized correlation coefficient between -1 and 1.