SUMXMY2 returns the sum of the squares of the differences between corresponding values in two arrays. It calculates (x − y)² for each pair and adds all those squared differences together.
=SUMXMY2(array_x, array_y)What does SUMXMY2 do?
SUMXMY2 is a Math & trigonometry function that compares two lists of numbers position by position. For every pair, it subtracts the second value from the first, squares that difference, and then adds all the squared results into one total. The result is always zero or positive, and a value of zero means the two arrays are identical in every position.
This matters because squared differences are the foundation of many accuracy checks. They stop positive and negative gaps from cancelling out, and they punish large errors more heavily than small ones. That makes SUMXMY2 a quick way to score how closely a forecast, a budget, or a set of measurements matches reality.
Imagine you manage a sales team and have monthly targets next to actual sales. You want one number that summarises total forecast error without positive and negative misses hiding each other. SUMXMY2 gives you that single score in one formula, and you can compare scores across regions or time periods to see where performance is furthest from plan.
When to use SUMXMY2
- Comparing forecast figures with actual results to score forecast accuracy.
- Checking whether two lists of measurements or audit counts match exactly.
- Scoring budget versus actual spending across departments.
- Measuring the gap between planned and actual production or inventory counts.
- Grading student marks against an answer key or expected score.
- Comparing two versions of a dataset to quantify how much they differ.
SUMXMY2 syntax
=SUMXMY2(array_x, array_y)| Argument | Required? | What to enter |
|---|---|---|
array_x | Required | The first range or array of numbers, such as actual values. Example: B2:B10. |
array_y | Required | The second range or array of numbers, such as expected values. It must have the same number of values as array_x. Example: C2:C10. |
What it returns: A single number: the sum of (x − y)² for every corresponding pair in the two arrays. The result is zero when the arrays match exactly and grows as differences increase.
SUMXMY2 examples
1 Example 1: Two short lists of numbers
This example compares three pairs of simple numbers. The formula pairs each value in B2:B4 with the value in the same row of C2:C4, subtracts, squares, and adds. The differences are 1, 2, and 3, which square to 1, 4, and 9. The total is 14.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Item | Value X | Value Y | |||
| 2 | A | 10 | 9 | 14 | ||
| 3 | B | 12 | 10 | |||
| 4 | C | 15 | 12 | |||
| 5 |
2 Example 4: Comparing two stock counts
A warehouse manager counts stock twice and wants to know how much the two counts differ overall. The formula pairs each item's first count in B2:B6 with its second count in C2:C6. The differences are 10, 20, 30, 40, and 50, which square to 100, 400, 900, 1600, and 2500. The total score is 5500, highlighting that the largest discrepancies matter most.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Item | Count 1 | Count 2 | |||
| 2 | Widget | 120 | 110 | 5500 | ||
| 3 | Gadget | 80 | 60 | |||
| 4 | Bolt | 200 | 170 | |||
| 5 | Nut | 150 | 110 | |||
| 6 | Screw | 90 | 40 | |||
| 7 |
3 Example 5: Small measurement differences
This example compares two sets of precise measurements, such as lab readings. The formula uses B2:B8 and C2:C8. The differences are 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, and 0.7, which square to 0.01, 0.04, 0.09, 0.16, 0.25, 0.36, and 0.49. Their sum is 1.4, so even small gaps add up in the squared score.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Reading | Set X | Set Y | |||
| 2 | R1 | 1.1 | 1 | 1.4 | ||
| 3 | R2 | 2.2 | 2 | |||
| 4 | R3 | 3.3 | 3 | |||
| 5 | R4 | 4.4 | 4 | |||
| 6 | R5 | 5.5 | 5 | |||
| 7 | R6 | 6.6 | 6 | |||
| 8 | R7 | 7.7 | 7 | |||
| 9 |
Common SUMXMY2 errors and how to fix them
| Error | Why it happens | How to fix it |
|---|---|---|
| #N/A | The two arrays contain a different number of values, so Excel cannot pair every item. | Make sure array_x and array_y cover the same number of rows or cells, 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 point the formula only at numeric cells. |
| Wrong total | The two ranges are offset, so values are paired with the wrong row. | Check that both ranges start and end on the same rows, such as B2:B10 with C2:C10. |
| #NUM! | A squared difference is too large for Excel to store, which is rare with normal business data. | Check for extremely large numbers or accidental text-to-number issues in the source cells. |
Tips for using SUMXMY2
- Use SUMXMY2 when you need one accuracy score; a result of zero means the two lists match exactly.
- Keep both ranges the same size and aligned row by row to avoid mismatched pairs.
- Because differences are squared, large errors dominate the score; inspect the largest gaps separately if you need detail.
- For a simpler total of differences without squaring, consider
SUMPRODUCTwith subtraction instead. - Label the result clearly, for example "Squared error score", so readers know it is not a currency amount.
Frequently asked questions
What does SUMXMY2 actually calculate?
It calculates (x − y)² for each pair of values in two arrays and returns the sum of all those squared differences.
Why is my SUMXMY2 result zero?
A zero result means every value in the first array equals the corresponding value in the second array, so all differences are zero.
Can SUMXMY2 compare text or dates?
It is designed for numbers. Text that looks numeric may be converted, but true text values can cause errors, so keep the ranges numeric.
How is SUMXMY2 different from SUMPRODUCT?
SUMXMY2 is a ready-made shortcut for the sum of squared differences. SUMPRODUCT is more flexible and can handle other calculations, such as SUMPRODUCT((B2:B10-C2:C10)^2).
Related functions
Every example on this page was recalculated by SheetSkill’s spreadsheet engine. SUMXMY2 reference