Aladin Educate Me Need Some Theory on Sumproduct

planetpj

Active Member
Joined
Jun 25, 2002
Messages
351
I have been studying sumproduct for a while. I just wanted to ask a couple of questions on board questions.
again.xls
ABCDE
1DepartmentTeamA616
2DepartmentTeamA716
3DivisionTeamA8
4DepartmentTeamB2
5DepartmentTeamA3
Sheet1


First I understand logic behind arrays. I understand the + sign signifies or and the * signifies and. My question is what does the comma signify. In the above example I broke sumproduct down two ways. One using * and the second using the comma. Both examples work so which one is better to use and why!! Second I read a post that you and IML did and the example was =SUMPRODUCT((TRUE)*({FALSE,TRUE})*5). I understand this example because the breakdown was great but there was a term that you used (MULTIPLYING A SCALAR WITH A VECTOR) can you please educate me on this term!!!!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
On 2002-10-15 09:38, planetpj wrote:
I have been studying sumproduct for a while. I just wanted to ask a couple of questions on board questions...

My question is what does the comma signify.

Commas separate the arguments within a function's parameter list. If you'll consult the Excel Help topic for "SUMPRODUCT worksheet function" you'll see the following...

SUMPRODUCT(array1,array2,array3, ...)

Array1, array2, array3, ... are 2 to 30 arrays whose components you want to multiply and then add.

See those commas between array1, array2, etc.
This message was edited by Mark W. on 2002-10-15 10:50
 
Upvote 0
The link to a thread

http://www.mrexcel.com/wwwboard/messages/8961.html

on the original board (now a CD) is made available on the current board.

The syntax of the target is...

SUMPRODUCT(Array1,Array2,Array3,...)

where Array1,... can also be read as Reference1, Reference2,... etc. All array arguments must be of numeric type.

As is clear from above, the comma is the list separator as in other functions, so there is nothing strange about it.

The formula in your example

[a]

=SUMPRODUCT((A1:A5="department")*(B1:B5="Team A"),C1:C5)

consists of 2 arrays:

[a.1]

(A1:A5="department")*(B1:B5="Team A")

[a.2]

C1:C5

Multiplication in [a.1] produces the first numeric array. When multiplied, the constant arrays of logicals results in a numeric array of 1's and 0's by coercion. So we have in [a] 2 numeric arrays that SUMPRODUCT multiplies and then sums.

If you'd be kosher, you should have 3 arrays...



=SUMPRODUCT((A1:A5="department")+0,(B1:B5="Team A")+0,C1:C5)

that is,

[b.1]

(A1:A5="department")+0

[b.2]

(B1:B5="Team A")+0

[b.3]

C1:C5

The arrays in [b.1] and [b.2] are indeed arrays of numeric type. Adding a 0 to an array of logicals coerce them into arrays of logicals... TRUE+0 ==> 1 and FALSE+0 ==> 0.

SUMPRODUCT multiplies numeric arrays [b.1], [b.2], and [b.3] and then sums.

Often you see the following...

[c]

=SUMPRODUCT((A1:A5="department")*(B1:B5="Team A")*C1:C5)

without comma. This leads after multiplication, again thru coercion, to just one numeric array which SUMPRODUCT then sums (that is, behaves like SUM)...say...

=SUM({2,0,12,20,0,0})

What must be preferred? One thing that is clear is that the comma version is not affected by text values or formula generated "" in the range/array/reference we want to conditionally sum.

When we need OR'ing, things get a bit complicated...

Let A2:B7 house the following sample...

{"a",5;"b",6;"a",4;"c",5;"a",7;"c",8},

E2 "a", and F2 "b".

[d]

=SUMPRODUCT(((A2:A7=E2)+(A2:A7=F2)),B2:B7)

would sum all values where A2:A7 houses either a value equal to E2 or to F2. The non-kosher version would be...

[e]

=SUMPRODUCT(((A2:A7=E2)+(A2:A7=F2))*B2:B7)

As I said above, [e] would give, rightly so, a #VALUE! error if B2:B7 contains any text value. It's normal to get such an error when we attempt a number with a text value. What is unusual is that [d], which obeys the syntax of the target function, is not affected in such cases.

Let E2 and F2 house "a" and "b", respectively.

The following formula, which we see very often,

[f]

=SUMPRODUCT((A2:A7={"a","b"})*B2:B7)

will also work, assuming there is no text value or "" in B2:B7.

{"a","b"} is what you get when select E2:F2 and apply F9 to the selection. This action shows you the "relation" or "correspondence" between a range and an array constant (This is apparently the reason why people often say "I have an array" instead of a range, while they mean the latter).

Note that {"a","b"} "corresponds" to a horizontal range, while {"a";"b"} to a vertical range.

Given the above correspondence between {"a","b"} and E2:F2, we can have

[g]

=SUMPRODUCT((A2:A7=B2:F2)*B2:B7)

which, I'm not surprised, IML noticed and inquired about. See

http://makeashorterlink.com/?V24535422

how non-obvious this formulation appears to be. In fact, what happens in [g] is a matrix manipulation (that is, why Beban is reminded of MMULT).

I'd like to add that the above also applies to formulas entered by using control+shift+enter.

HTH

Aladin
 
Upvote 0
I have deleted my posting.
This message was edited by gnaga on 2002-10-15 11:09
 
Upvote 0
Aladin & Mark thank you both for answering my question. So many times we take for granted how great that this board is. I don't know if we really realize how much information goes through the board each day and how educated we can get by just reading. It is an education within it self. I thank you both along with many others who take the time to answer my questions and help me succeed to better understand formulas & functions in excel
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,483
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top