Math & trig function

SUMXMY2 function

Adds the squared differences between matching values in two arrays, the basis of RMSE and least squares.

Available in All versions of Excel, Excel for the web, Excel for Mac

In every Excel versionWorks in Google Sheets

Syntax

SUMXMY2(array_x, array_y)
ArgumentWhat it means
array_xRequiredThe first range, e.g. forecasts.
array_yRequiredThe second range, e.g. actual results. Same number of values.

Returns: Σ(x − y)² over all pairs.

How SUMXMY2 works

SUMXMY2 ("sum of x minus y, squared") is the most practical of the three pair-of-squares functions. For each row it takes the difference between two values, squares it and adds everything up. That is exactly the sum of squared errors (SSE) used to judge forecasts, compare measurements with targets, or fit a model by least squares.

Because the difference is squared, a miss of 8 counts four times as much as a miss of 4, so big errors dominate. Divide by the count and take the square root to get the root mean square error (RMSE) in the original units. Pairs containing text or blanks are skipped; unequal sizes return #N/A.

Examples

1Sum of squared forecast errors

B7fx=SUMXMY2(B2:B6, C2:C6)
ABC
1MonthForecastActual
2Jan120114
3Feb135141
4Mar128120
5Apr140143
6May150146
7161

Result: 161

Differences 6, −6, 8, −3, 4 squared give 36 + 36 + 64 + 9 + 16 = 161.

2Root mean square error

B8fx=SQRT(SUMXMY2(B2:B6, C2:C6)/COUNT(B2:B6))
ABC
1MonthForecastActual
2Jan120114
3Feb135141
4Mar128120
5Apr140143
6May150146
7
85.67

Result: 5.67

√(161 / 5) ≈ 5.67 units: on average the forecast is about 5.7 units away from reality (2 decimals).

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 14 KB

Common errors and how to fix them

ErrorWhy it happensFix
#N/ARanges of different sizes.Use equally sized ranges.

Tips

  • Compare two forecasting methods by their SUMXMY2 against the same actuals: the lower one fits better.
  • For average absolute error (MAE) use =AVERAGE(ABS(B2:B6-C2:C6)) in Microsoft 365.

Google Sheets

SUMXMY2 also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.

SUMXMY2 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.

LanguageFunction name
DutchSOM.XMINY.2
FinnishEROTUSTEN.NELIÖSUMMA
FrenchSOMME.XMY2
GermanSUMMEXMY2
HungarianSZUMXBŐLY2
ItalianSOMMA.Q.DIFF
Norwegian (Bokmål)SUMMERXMY2
PolishSUMA.XMY.2
Portuguese (Brazil)SOMAXMY2
Portuguese (Portugal)SOMAXMY2
RussianСУММКВРАЗН
SpanishSUMAXMENOSY2
SwedishSUMMAXMY2
TurkishTOPXEY2