excel - How does the SUMPRODUCT command works in this example? -


the following code allows me determine distinct values in pivot table in excel:

=sumproduct(($a$a:$a2=a2)*($b$2:$b2=b2)) 

see also: simple pivot table count unique values

the code runs fine. however, can me understand how code works?

you write: following code allows me determine distinct values in pivot table in excel

no. formula alone not that. read on explanation of does.

there's typo in formula. should be

=sumproduct(($a$2:$a2=a2)*($b$2:$b2=b2)) 

see difference?

the formula starts in row 2 , copied down. in each row, $a$2 reference , $b$2 reference stay same. $ signs make them absolute references. relative references $a2 , a2 change row numbers when copied down, in row 3 a2 change a3 , b2 change b3. in next row a4 , b4, , on.

you may want create sample scenario data similar in thread link to. use "evaluate formula" tool on formulas ribbon see step step calculated. formula evaluates inside out. let's assume formula has been copied down row 5 , looking at

=sumproduct(($a$2:$a5=a5)*($b$2:$b5=b5)) 

($a$2:$a5=a5) bit compares cells a2 a5 value in a5. result array of 4 values, either true or false. next bit ($b$2:$b5=b5) returns array of true or false values.

enter image description here

these 2 arrays multiplied , result array of 1 or 0 values. each array has same number of values.

the first value of first array multiplied first value of second array. (see red arrows)

the second value of first array multiplied second value of second array. (see blue arrows)

and on.

true * true return 1, else return 0. result of multiplication is:

enter image description here

the nature of sumproduct function sum result of multiplications (the product), does.

this function alone not @ establish distinct values in excel. in thread link to, sumproduct wrapped in if statement , distinct values identified.

=if(sumproduct(($a$2:$a2=a2)*($b$2:$b2=b2))>1,0,1)

in plain words: if combination of value in column of current row , column b of current row has appeared above, return zero, otherwise, return 1.

this marks distinct values of combined columns , b.


Comments

Popular posts from this blog

python - argument must be rect style object - Pygame -

c++ - Qt setGeometry: Unable to set geometry -

webrtc - Which ICE candidate am I using and why? -