How to use the SUMXMY2 function
What is the SUMXMY2 function?
The SUMXMY2 function calculates the sum of squares of differences of corresponding values in two arrays.
Table of Contents
1. Introduction
What is the square?
In mathematics, the square of a number is the result of multiplying the number by itself. Squaring a number is denoted by x2. For example, 52 means 5 * 5 = 25.
Squaring a number results in a positive result as negative signs are removed in multiplication. (-5)2 = 25 Squares grow very rapidly. Already x2 reaches large values quickly as x increases, higher powers grow even faster.
The square root is the inverse operation of squaring. √25 = 5, since squaring 5 gives 25. Squaring is used in geometry to calculate area of squares, side length squared = area. Squaring is also used when calculating the area of a circle.
For example, A = π r²
A is the area.
r is the radius.
π is pi.
The graph of y = x2 is a parabola, symmetric about the origin.
Squares appear frequently in equations in physics, math, statistics, and other fields.
What is the sum of squares of differences of corresponding values in two arrays?
SUMXMY2 stands for the sum of (x - y)2
or
SUMX2MY2 = ∑ (x1 - y1)2 + (x2 - y2)2 + ... + (xn - yn)2
What is the difference between SUMXMY2 function and SUMX2MY2 function?
The main difference between the SUMXMY2 and SUMX2MY2 functions in Excel is that the SUMXMY2 calculate the sum of squares of differences of corresponding values in two arrays while the SUMX2MY2 sums the of squares of differences of two arrays.
For example:
Array1 = {1, 3, 5}
Array2 = {2, 4, 6}
SUMXMY2(Array1, Array2) = (1 - 2)2 + (3 - 4)2 + (5 - 6)2 = 3
SUMX2MY2(Array1, Array2) = (12 - 22) + (32 - 42) + (52 - 62) = -3 + (-7) + (-11) = -21
So SUMXMY2 is a direct difference, while SUMX2MY2 differences the squares.
2. Syntax
SUMX2MY2(array_x, array_y)
array_x | Required. The first array or range of values. |
array_y | Required. The second array or range of values. |
3. Example 1
This example demonstrates how to use the SUMXMY2 function. The above image shows the input values in B3:B5 and C3:C5 respectively.
The image above shows two arrays, the first cell range (B3:B5) contains 4, 3, and 4 and the second cell range (C3:C5) contains 2, 3, and 4.
Formula in cell F3:
The result is displayed in cell F3 and it shows 12. Lets calculate this value manually:
(B3 - C3)² + (B4 - C4)² + (B5 - C5)²
The first array array_x i 4, 3, and 4. The second array contains 2, 3, and 4. The sum of the difference of squares:
(4 - 2)² = 2² = 4
(3 - 3)² = 0² = 0
(4 - 4)² = 0² = 0
The sum is 4 + 0 + 0 equals 4.
4. Example 2
What is the distance between coordinate 1 (1, 2) and coordinate 2 (11, 8)?
What we know:
- A coordinate has an x value and a y value (x, y)
- Coordinate 1 (1,2): x = 1 and y = 2
- Coordinate 2 (11,8): x = 11 and y = 8
Formula in cell C22:
=SQRT(SUMXMY2(C18:D18,C19:D19))
The formula in cell C22 returns approx. 11.66 units which represents the distance between coordinate 1 (1,2) and coordinate 2 (11,8).
The Pythagorean theorem lets you calculate the distance between two points on the Cartesian plane.
c2 = a2 + b2
- c is the distance
- a is equal to x2 - x1 which is 11 - 1 = 10
- be is equal to y2 - y1 which is 8 - 2 = 6
c = √(a2 + b2)
c = √(102 + 62)
c = √(100 + 36)
c = √136
c is approx. 11.66 units
5. Example 3
In a scientific study, you've collected data on the lengths of individuals from a particular animal species. To quantify how much these lengths vary within the population, calculate the population standard deviation of the recorded length measurements?
Here are the data points: 40, 76, 60, 31, 27, 42, 60, 59, 42, and 43
What we know:
The formula for calculating the standard deviation of a population is:
σ = √(∑(x - μ)²) / N
- x are data points
- μ is the average of the data points
- N is the total number of data points
The formula in cell range C16:C25 calculates the average, we need the value in as many cells as there are data points.
Formula in cell F15:
This formula returns 14.44 which represents the standard deviation for a population. This is what the formula calculates in greater detail:
standard deviation for the population σ = √(∑(x - μ)²) / N
- Calculate the difference,then square the difference, and finally add the squared values. ∑(x - μ)²
SUMXMY2(B16:B25,C16:C25) - Divide the total with the number of data points (∑(x - μ)²) / N
SUMXMY2(B16:B25,C16:C25)/ROWS(B16:B25) - Square the ratio (√(∑(x - μ)²) / N).
SQRT(SUMXMY2(B16:B25,C16:C25)/ROWS(B16:B25))
Lets calculate the standard deviation manually:
The average is calculated like this:
μ = ∑xᵢ / n
-
- ∑ (sigma) represents the sum
- i is the index that goes from 1 to n
- n is the total number of values
The total of 40, 76, 60, 31, 27, 42, 60, 59, 42, and 43 is 480.
480/10 = 48
Subtract each data point with the average:
40 - 48 = -8
76 - 48 = 28
60 - 48 = 12
31 - 48 = -17
27 - 48 = -21
42 - 48 = -6
60 - 48 = 12
59 - 48 = 11
42 - 48 = -6
43 - 48 = -5
Square the difference and then add the numbers
-8² = 64
28² = 784
12² = 144
-17² = 289
-21² = 441
-6² = 36
12² = 144
11² = 121
-6² = 36
-5² = 25
64 + 784 + 144 + 289 + 441 + 36 + 144 + 121 + 36 + 25 = 2084
Divide the total with the number of data points
2084 / 10 = 208.4
Square the ratio
√208.4 = 14.4360659460949
Excel has dedicated formulas for calculating the standard deviation: STDEV.S and STDEV.P functions. These functions are easier to work with than the formula I created above.
6. Example 4
A company that specializes in predicting energy consumption for households has developed a new model to forecast daily energy usage. The model uses historical data and weather forecasts to make predictions. The company wants to evaluate the performance of the model by comparing its predictions to the actual energy consumption of 5 households over a period of 6 days. Calculate the Mean Squared Error (MSE) between the predicted and actual values?
Where:
- Predicted is the range of predicted values (C3:C8)
- Actual is the range of actual values (E3:E8)
- COUNT(Predicted) is the number of data points (6)
The formula in cell G3:
This formula calculates the Mean Squared Error (MSE) between two sets of values.
Here is a break-down:
- SUMXMY2(C3:C8, E3:E8): This part of the formula calculates the sum of the squared differences between the values in columns C and E, from rows 3 to 8.
- COUNTA(B3:B8): This part of the formula counts the number of non-blank cells in column B, from rows 3 to 8.
- SUMXMY2(C3:C8,E3:E8)/COUNTA(B3:B8): The formula then divides the sum of the squared differences by the count of non-blank cells in column B.
7. Function not working
SUMXMY2 returns the
- #N/A error value if array_x and array_y have a different number of values.
- #NAME? error if you misspell the function name.
- propagates errors, meaning that if the input contains an error (e.g., #VALUE!, #REF!), the function will return the same error.
7.1 Troubleshooting the error value
When you encounter an error value in a cell a warning symbol appears, displayed in the image above. Press with mouse on it to see a pop-up menu that lets you get more information about the error.
- The first line describes the error if you press with left mouse button on it.
- The second line opens a pane that explains the error in greater detail.
- The third line takes you to the "Evaluate Formula" tool, a dialog box appears allowing you to examine the formula in greater detail.
- This line lets you ignore the error value meaning the warning icon disappears, however, the error is still in the cell.
- The fifth line lets you edit the formula in the Formula bar.
- The sixth line opens the Excel settings so you can adjust the Error Checking Options.
Here are a few of the most common Excel errors you may encounter.
#NULL error - This error occurs most often if you by mistake use a space character in a formula where it shouldn't be. Excel interprets a space character as an intersection operator. If the ranges don't intersect an #NULL error is returned. The #NULL! error occurs when a formula attempts to calculate the intersection of two ranges that do not actually intersect. This can happen when the wrong range operator is used in the formula, or when the intersection operator (represented by a space character) is used between two ranges that do not overlap. To fix this error double check that the ranges referenced in the formula that use the intersection operator actually have cells in common.
#SPILL error - The #SPILL! error occurs only in version Excel 365 and is caused by a dynamic array being to large, meaning there are cells below and/or to the right that are not empty. This prevents the dynamic array formula expanding into new empty cells.
#DIV/0 error - This error happens if you try to divide a number by 0 (zero) or a value that equates to zero which is not possible mathematically.
#VALUE error - The #VALUE error occurs when a formula has a value that is of the wrong data type. Such as text where a number is expected or when dates are evaluated as text.
#REF error - The #REF error happens when a cell reference is invalid. This can happen if a cell is deleted that is referenced by a formula.
#NAME error - The #NAME error happens if you misspelled a function or a named range.
#NUM error - The #NUM error shows up when you try to use invalid numeric values in formulas, like square root of a negative number.
#N/A error - The #N/A error happens when a value is not available for a formula or found in a given cell range, for example in the VLOOKUP or MATCH functions.
#GETTING_DATA error - The #GETTING_DATA error shows while external sources are loading, this can indicate a delay in fetching the data or that the external source is unavailable right now.
7.2 The formula returns an unexpected value
To understand why a formula returns an unexpected value we need to examine the calculations steps in detail. Luckily, Excel has a tool that is really handy in these situations. Here is how to troubleshoot a formula:
- Select the cell containing the formula you want to examine in detail.
- Go to tab “Formulas” on the ribbon.
- Press with left mouse button on "Evaluate Formula" button. A dialog box appears.
The formula appears in a white field inside the dialog box. Underlined expressions are calculations being processed in the next step. The italicized expression is the most recent result. The buttons at the bottom of the dialog box allows you to evaluate the formula in smaller calculations which you control. - Press with left mouse button on the "Evaluate" button located at the bottom of the dialog box to process the underlined expression.
- Repeat pressing the "Evaluate" button until you have seen all calculations step by step. This allows you to examine the formula in greater detail and hopefully find the culprit.
- Press "Close" button to dismiss the dialog box.
There is also another way to debug formulas using the function key F9. F9 is especially useful if you have a feeling that a specific part of the formula is the issue, this makes it faster than the "Evaluate Formula" tool since you don't need to go through all calculations to find the issue..
- Enter Edit mode: Double-press with left mouse button on the cell or press F2 to enter Edit mode for the formula.
- Select part of the formula: Highlight the specific part of the formula you want to evaluate. You can select and evaluate any part of the formula that could work as a standalone formula.
- Press F9: This will calculate and display the result of just that selected portion.
- Evaluate step-by-step: You can select and evaluate different parts of the formula to see intermediate results.
- Check for errors: This allows you to pinpoint which part of a complex formula may be causing an error.
The image above shows cell reference B3:B5 converted to hard-coded value using the F9 key. The SUMXMY2 function requires numerical values which is not the case in this example. We have found what is wrong with the formula.
Tips!
- View actual values: Selecting a cell reference and pressing F9 will show the actual values in those cells.
- Exit safely: Press Esc to exit Edit mode without changing the formula. Don't press Enter, as that would replace the formula part with the calculated value.
- Full recalculation: Pressing F9 outside of Edit mode will recalculate all formulas in the workbook.
Remember to be careful not to accidentally overwrite parts of your formula when using F9. Always exit with Esc rather than Enter to preserve the original formula. However, if you make a mistake overwriting the formula it is not the end of the world. You can “undo” the action by pressing keyboard shortcut keys CTRL + z or pressing the “Undo” button
7.3 Other errors
Floating-point arithmetic may give inaccurate results in Excel - Article
Floating-point errors are usually very small, often beyond the 15th decimal place, and in most cases don't affect calculations significantly.
Functions in 'Math and trigonometry' category
The SUMXMY2 function function is one of 62 functions in the 'Math and trigonometry' category.
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form