Difference between revisions of "Documentation/How Tos/Calc: SUMPRODUCT function"

From Apache OpenOffice Wiki
Jump to: navigation, search
(Example:)
Line 28: Line 28:
 
: when entered 'normally' (not as an [[Documentation/How_Tos/Using Arrays|array formula]]), returns the sum of the absolute values in cells <tt>'''A1:A6'''</tt>. <tt>'''SUMPRODUCT'''</tt> forces <tt>'''ABS(A1:A6)'''</tt> to be evaluated as an [[Documentation/How_Tos/Using Arrays|array formula]].
 
: when entered 'normally' (not as an [[Documentation/How_Tos/Using Arrays|array formula]]), returns the sum of the absolute values in cells <tt>'''A1:A6'''</tt>. <tt>'''SUMPRODUCT'''</tt> forces <tt>'''ABS(A1:A6)'''</tt> to be evaluated as an [[Documentation/How_Tos/Using Arrays|array formula]].
  
<tt>'''SUMPRODUCT(A1:A6="red" * B1:B6="big" * C1:C6)'''</tt>
+
<tt>'''SUMPRODUCT(A1:A6="red"; B1:B6="big"; C1:C6)'''</tt>
:returns the sum of cells in <tt>'''C1:C6'''</tt> whose corresponding entries in the A column are <tt>'''red'''</tt> and in the B column are <tt>'''big'''</tt>. Note that the construction <tt>'''SUMPRODUCT(A1:A6="red"; B1:B6="big"; C1:C6)'''</tt> also works in Calc, but is not portable to Excel.
+
:returns the sum of cells in <tt>'''C1:C6'''</tt> whose corresponding entries in the A column are <tt>'''red'''</tt> and in the B column are <tt>'''big'''</tt>. This is not portable to Excel, as Excel ignores logical values.
 +
 
 +
<tt>'''SUMPRODUCT((A1:A6="red") * (B1:B6="big") * C1:C6)'''</tt>
 +
:a version of <tt>'''SUMPRODUCT(A1:A6="red"; B1:B6="big"; C1:C6)'''</tt> which is portable to Excel, as the logical values are converted to numbers during the multiplication.
  
 
=== See also: ===
 
=== See also: ===
Line 49: Line 52:
  
 
=== Issues: ===
 
=== Issues: ===
*SUMPRODUCT in Excel ignores logical values, so for example <tt>'''SUMPRODUCT(A1:A6="red"; B1:B6="big"; C1:C6)'''</tt> does not work in Excel. One solution is to use * as in: <tt>'''SUMPRODUCT(A1:A6="red" * B1:B6="big" * C1:C6)'''</tt>; this forces the logical values to convert to numbers.
+
*SUMPRODUCT in Excel ignores logical values (that is, it treats them as 0). In Calc <tt>'''TRUE'''</tt> is 1 and <tt>'''FALSE'''</tt> is 0.

Revision as of 07:26, 22 September 2008


SUMPRODUCT

Returns the sum of the products of corresponding array elements.

Syntax:

SUMPRODUCT(array1; array2; ... array30)

array1 to array30 are up to 30 arrays or ranges of the same size whose corresponding elements are to be multiplied.
SUMPRODUCT returns Calc sumproduct equation.png for the i elements in the arrays.
You can use SUMPRODUCT to calculate the scalar product of two vectors.


Advanced topic:
SUMPRODUCT evaluates each parameter array1 to array30 as an array formula, but does not need to be entered as an array formula. In other words it can be entered with the Enter key, rather than Cntrl-Shift-Enter. See the example below.
SUMPRODUCT can also be used to sum cells where a specified condition is true - see Conditional Counting and Summation and the example below.

Example:

SUMPRODUCT(A1:B2; F1:G2)

returns A1*F1 + B1*G1 + A2*F2 + B2*G2.

Advanced topic:

SUMPRODUCT(ABS(A1:A6))

when entered 'normally' (not as an array formula), returns the sum of the absolute values in cells A1:A6. SUMPRODUCT forces ABS(A1:A6) to be evaluated as an array formula.

SUMPRODUCT(A1:A6="red"; B1:B6="big"; C1:C6)

returns the sum of cells in C1:C6 whose corresponding entries in the A column are red and in the B column are big. This is not portable to Excel, as Excel ignores logical values.

SUMPRODUCT((A1:A6="red") * (B1:B6="big") * C1:C6)

a version of SUMPRODUCT(A1:A6="red"; B1:B6="big"; C1:C6) which is portable to Excel, as the logical values are converted to numbers during the multiplication.

See also:

SUM, SUMIF, SUMSQ, SUMX2MY2, SUMX2PY2, SUMXMY2

Conditional Counting and Summation

How To Use Arrays in Calc

Array functions

Functions listed alphabetically, Functions listed by category

Issues:

  • SUMPRODUCT in Excel ignores logical values (that is, it treats them as 0). In Calc TRUE is 1 and FALSE is 0.
Personal tools