SUMX2MY2 adds up the difference between the squares of two matching arrays: it calculates x² − y² for each pair and returns the total. It is a compact way to compare paired values without building an extra helper column.
=SUMX2MY2(array_x, array_y)What does SUMX2MY2 do?
SUMX2MY2 is a Math & trigonometry function that takes two arrays of numbers, squares each value in the first array, squares each value in the second array, subtracts the second square from the first for every pair, and adds all those differences together. In plain terms, it returns Σ(x² − y²) for two equal-sized ranges.
The function matters because it removes the need for a helper column when you want to compare paired measurements. Instead of squaring both columns row by row and then summing, you point SUMX2MY2 at the two ranges and get one answer. That keeps worksheets cleaner and reduces formula clutter.
A typical situation is comparing two sets of paired readings, such as forecast versus actual sales, before and after weights, or two instrument measurements. If the two arrays are identical, the result is zero, which makes SUMX2MY2 a quick check for whether paired values match exactly.
When to use SUMX2MY2
- Comparing forecast and actual values for the same periods.
- Checking whether two paired measurement columns are identical.
- Calculating the sum of squared differences for paired samples.
- Summarising before-and-after readings without helper columns.
- Auditing two lists of paired quantities for discrepancies.
SUMX2MY2 syntax
=SUMX2MY2(array_x, array_y)| Argument | Required? | What to enter |
|---|---|---|
array_x | Required | The first range or array of numbers. Each value is squared before the subtraction. Example: B2:B10. |
array_y | Required | The second range or array of numbers, the same size as array_x. Each value is squared and subtracted from the matching x square. Example: C2:C10. |
What it returns: A single number: the sum of x² − y² across all matching pairs in the two arrays.
SUMX2MY2 examples
1 Simple paired numbers
This example uses three pairs of small numbers to show the basic calculation. SUMX2MY2 squares each value in B2:B4 and C2:C4, subtracts the y square from the x square for each row, and adds the three differences. The row results are 9 − 4 = 5, 16 − 1 = 15, and 25 − 9 = 16, giving a total of 36. The formula returns 36.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Pair | X | Y | |||
| 2 | 1 | 3 | 2 | 36 | ||
| 3 | 2 | 4 | 1 | |||
| 4 | 3 | 5 | 3 | |||
| 5 |
2 Identical arrays return zero
This example checks whether two measurement columns are exactly the same. Because every value in B2:B6 equals the matching value in C2:C6, each x² − y² difference is zero, and the total is zero. The formula returns 0, which confirms the two columns match.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Sample | Reading A | Reading B | |||
| 2 | 1 | 10 | 10 | 0 | ||
| 3 | 2 | 12 | 12 | |||
| 4 | 3 | 14 | 14 | |||
| 5 | 4 | 16 | 16 | |||
| 6 | 5 | 18 | 18 | |||
| 7 |
Common SUMX2MY2 errors and how to fix them
| Error | Why it happens | How to fix it |
|---|---|---|
| #N/A | The two arrays have different numbers of values, so Excel cannot pair every x with a y. | Make both ranges the same size, for example B2:B10 and C2:C10. |
| #VALUE! | One or more cells contain text that cannot be converted to a number. | Remove or correct text entries in the ranges, or use IFERROR around the formula if text is expected. |
| #NUM! | A value is too large to square within Excel's numeric limits. | Check for extremely large numbers and scale the data down before using SUMX2MY2. |
| Wrong total | The ranges are offset or include a different number of rows than intended. | Verify that both ranges start and end on the same rows and refer to the correct columns. |
Tips for using SUMX2MY2
- Use SUMX2MY2 when you need Σ(x² − y²); use SUMXMY2 when you need Σ(x − y)².
- Both ranges must be the same size; select them together to avoid mismatches.
- If the result is zero, the two arrays are identical in value.
- Remember that squaring magnifies differences, so large values produce very large results.
- Keep the two ranges in the same orientation (both columns or both rows).
Frequently asked questions
What does SUMX2MY2 calculate?
It returns the sum of x² − y² for each matching pair in two arrays, which is Σ(x² − y²).
How is SUMX2MY2 different from SUMXMY2?
SUMX2MY2 subtracts the squares (x² − y²), while SUMXMY2 squares the difference ((x − y)²).
Why does SUMX2MY2 return zero?
A zero result means every value in the first array equals the matching value in the second array.
Can SUMX2MY2 handle text or blank cells?
Text that cannot be converted to a number causes #VALUE!; blank cells are treated as zero in many cases, so check your ranges.
Related functions
Every example on this page was recalculated by SheetSkill’s spreadsheet engine. SUMX2MY2 reference