Let's talk about Excel's SUMPRODUCT function
This article brings you relevant knowledge about excel, which mainly introduces the related issues of the SUMPRODUCT function. This function not only integrates the two major functions of conditional summation and counting, but also It can be used for ranking processing in complex scenarios. Let’s take a look at it. I hope it will be helpful to everyone.
Related learning recommendations: excel tutorial
Today I will share with you a very commonly used and practical function: SUMPRODUCT. As we all know, conditional summation and counting are the two most common problems encountered by table users, and this function not only combines the two major functions of conditional summation and counting; it can also be used for ranking processing in complex scenarios, and even heard that Some people have conquered half of the Excel world with just one function...so they have to learn it.
Basic syntax
Let’s look at the basic syntax first. The official syntax description of SUMPRODUCT is to add the corresponding elements between the arrays in given sets of arrays. Multiply and return the sum of the products. The syntax format is as follows:
=SUMPRODUCT(array1,array2,array3, …)
- SUM means summation, PRODUCT means multiplication. The parameters are multiplied and then summed. You see, SUMPRODUCT does exactly what its name suggests.
Look at my hand, Wai, Tu, Sri... To sum up, the SUMPRODUCT function has the following three characteristics:
1> It performs array operations by default.
2> It will treat non-numeric array elements in the parameters as 0.
3> The parameters must have the same size, otherwise an error value will be returned.
Characteristic Analysis
After reading SUMPRODUCT’s resume, many friends must be looking at it in the fog and only have a vague understanding of it. What do these characteristics of it mean? What kind of work can it do? In fact, it is not clear.
Snap your fingers and let me give you a few examples.
As shown in the data table above, column C is the unit price of the product, and column D is the sales quantity. Now we need to calculate the total sales in cell C9.
C9 Enter the following formula to get the result 11620.60
=SUMPRODUCT(C3:C7, D3:D7)
This is a simple SUMPRODUCT function. Its operation process is: multiply the elements in the two area arrays C3:C7 and D3:D7 respectively, that is, C3*D3, C4*D4, C5*D5... until C7*D7
It means first calculating the sales amount of each product, and finally summing it up.
Because the first feature of the SUMPRODUCT function is that it supports operations between arrays, although the formula performs multiple operations, there is no need to press the triple array key
Some friends said that the formula can also be written like this:
=SUMPRODUCT(C3:C7*D3:D7)
Or you can use the following array formula.
=SUM(C3:C7*D3:D7)
So what are the differences between these three formulas?
First of all, in most cases, the SUMPRODUCT function does not require the array triple key to end the formula input to perform array operations, but the SUM function does.
Secondly, let’s talk about another very important feature of the SUMPRODUCT function.
......
We have slightly changed the above table and changed the sales quantity of "pens" to: Not yet counted. It is also necessary to calculate the total sales in cell C9.
At this time, if you use the formula:
=SUMPRODUCT(C3:C7*D3:D7)
or the array formula:
=SUM(C3:C7*D3:D7)
, the error value #VALUE!## will be returned.
#The reason for returning the error value is that cell D4 is "not yet counted" as a text value. Text values cannot directly participate in mathematical operations, so C4*D4 returns the error value #VALUE!, which in turn causes the result of the entire formula to be returned. Error value. There is no such problem when using the following formula, and the correct result will be returned directly: =SUMPRODUCT(C3:C7,D3:D7)This is SUMPRODUCT The second feature of the function: treat non-numeric array elements as 0. Take this example, the value of cell D4 "not yet counted" is text, not a numerical value. SUMPRODUCT actively treats it as zero, so C4*D4, the result is also zero, and the other array elements are as usual Calculate and get the result of 11385.60. It should be noted that SUMPRODUCT treats non-numeric array elements as 0. The so-called non-numeric array elements include logical values and text, but do not contain error values. If the array element contains Error value, the formula also returns an error value, such as the first formula in this example. ……After talking about the two features of the SUMPRODUCT function, let’s talk about its third feature: the array parameters must have the same size, otherwise an error value will be returned. We still use the example in the above picture as an example to continue to calculate the total sales of the product. If we enter the formula in C9:=SUMPRODUCT(C3:C7,D3:D6)
细心的你肯定已经注意到了,两个区域数组,C3:C7明显显比D3:D6多了一个元素,C3和D3结对子,C4和D4结对子……那么C7和谁结对子呢?女人们都嫁了,结果剩下一个光棍,这日子没法过了!一个萝卜一个坑,只有萝卜没有坑,这不是要萝卜死吗?
——于是SUMPRODUCT就不高兴了,它给你一个错误值#VALUE!,明确告诉你,和谐时代幸福岁月,日子不能这么过。
这就是SUMPRODUCT函数的第三个特点:数组参数必须有相同的尺寸,否则返回错误值。
下面是一道练习题,你看看,能用SUMPRODUCT函数做出来吗?
案例拓展
假设下面这张图,是某个公司工资发放的部分记录表(数据纯属虚拟,如有雷同,那是穿越)。A列是工资发放的时间,B列是员工所属的部门,C列是员工姓名,D列是相关员工领取的工资金额。
——那么,问题和广告都来了:
1
员工西门庆领取了几次工资?
这是一个单条件计数的问题,通常我们使用COUNTIF函数,但如果使用SUMPRODUCT函数,一般写成这样:
=SUMPRODUCT((C2:C13="西门庆")*1)
先判断C2:C13的值是否等于”西门庆”,相等则返回TRUE,不等则返回FALSE,由此建立一个有逻辑值构成的内存数组。
上文已经说过,SUMPRODUCT有一个特性,它会将非数值型的数组元素作为0处理,逻辑值自然是属于非数值型的数组元素,为了避免SUMPRODUCT函数把逻辑值视为0,造成统计错误,我们使用*1的方式,把逻辑值转化为数值,TRUE转化为1,FALSE转化为0,最后统计求和。
2
员工西门庆领取了多少工资?
这是一个单条件求和的问题,通常我们使用SUMIF函数,如果使用SUMPRODUCT函数,我们可以写成这样:
=SUMPRODUCT((C2:C13="西门庆")*D2:D13)
依然首先判断C2:C13的值是否等于”西门庆”,得到逻辑值FALSE或TRUE,再和D2:D13的值对应相乘。TRUE乘以数值,得到数值本身。FALSE乘以数值返回0。最后统计求和得出结果。
看完了上面两个问题,有些朋友可能会在心里想,貌似SUMPRODUCT能干的事,SUMIF和COUNTIF也能做到,而且做的更好,那么还要SUMPRODUCT干啥嘞?
乡亲们呐,话不能这么说,SUMPRODUCT可是上得厅堂下得厨房,对工作环境不挑不拣,它对参数类型没有啥特别要求,COUNTIF和SUMIF就不同了,他俩要求个别参数,必须是区域(Range型),不支持数组,比如下面这两个问题,COUNTIF和SUMIF就要绕了。
3
二月份外交部发放了几次工资?总额是多少?
第1个问题,二月份外交部发放了几次工资?
这是一个多条件计数的问题。
第一个条件,发放工资的时间必须是二月份;第二个条件,发放工资的部门必须是外交部。
如果使用多条件计数函数COUNTIFS,判断发放工资的时间是否属于六月份,会简单问题复杂化。而使用SUMPRODUCT函数,咱们可以把公式写成这样:
=SUMPRODUCT((MONTH(A2:A13)=2)*(B2:B13="外交部"))
……
第2个问题,统计二月份外交部发放了多少工资?
这是一个常见的多条件求和问题。
如果使用SUMIFS函数,判断发放工资的时间是否属于六月份,也会简单问题复杂化。
SUMPRODUCT跃然而至:
=SUMPRODUCT((MONTH(A2:A13)=6)*(B2:B13="外交部"),D2:D13)
或者:
=SUMPRODUCT((MONTH(A2:A13)=6)*(B2:B13="外交部")*D2:D13)
打个响指,关于这两个形式的SUMPRODUCT函数的区别,咱们上文已有详细说明——你还记得吗?
上面这个公式可以说是SUMPRODUCT多条件求和的典型用法啦,可以归纳为:
=SUMPRODUCT((条件一)*(条件二)……,求和区域)
4
二月份外交部和步兵部合计发放了多少工资?
解决了上面的问题,相信大家已经晓得如何计算二月份外交部发放多少工资了,那么二月份外交部和步兵部合计发了多少工资,又当怎么计算呢
我们经常见有些性格朴素的表亲们把公式写成这样:
=SUMPRODUCT((MONTH(A2:A13)=2)*(B2:B13="外交部")*D2:D13)+SUMPRODUCT((MONTH(A2:A13)=2)*(B2:B13="步兵部")*D2:D13)
这些表亲们估计心想,不就是计算两个部门吗?甭说两个,二十个咱也能算,一个加一个,一直加到二十个,世上无难事,只怕有心人嘛,一砖加一砖,长城就建成了,一泡加一泡,长江就奔流了……
呃……公式写的那么长,先不谈计算速度,首先它累手啊,万一写错了,又要修改,那也是麻烦他妈哭麻烦——麻烦死了。
其实我们可以写成这样:
=SUMPRODUCT((MONTH(A2:A13)=6)*(B2:B13={"外交部","步兵部"})*D2:D13)
5
排名应用
认识了SUMPRODUCT函数在条件计数和求和方面的用法,最后,咱们再来看一个它在排名上的使用方法。
如上图所示,某个月某个公司某些人领了某些工资,然后呢,他们想看看自己的工资,在部门内的排名情况,比如说步兵部的鲁智深都是老员工了,非常想知道自个工资在各自部门排几号。
当然啦,不排不知道,一排就傻掉。
SUMPRODUCT是这么解决这个问题的,D2输入公式向下复制:
=SUMPRODUCT(($A$2:$A$9=A2)*(C2<$C$2:$C$9))+1
(思考,为什么公式的最后+1,而不是直接写成如下:)
=SUMPRODUCT(($A$2:$A$9=A2)*(C2<=$C$2:$C$9))
结束语
唠唠叨叨说了这么多,眼睛都说酸麻了,是到了该结束的时候啦。
最后,请思考两个小问题:
第1个问题:下面SUMPRODUCT函数有几个参数?
=SUMPRODUCT((MONTH(A2:A13)=6)*(B2:B13="财务部")*D2:D13)
下面这个SUMPRODUCT函数又有几个参数?
=SUMPRODUCT((MONTH(A2:A13)=6)*(B2:B13="财务部"),D2:D13)
第二个问题:
SUMPRODUCT为什么有时候比SUMIF/COUNTIF计算速度慢?
相关学习推荐:excel教程
The above is the detailed content of Let's talk about Excel's SUMPRODUCT function. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



If when opening a file that needs to be printed, we will find that the table frame line has disappeared for some reason in the print preview. When encountering such a situation, we must deal with it in time. If this also appears in your print file If you have questions like this, then join the editor to learn the following course: What should I do if the frame line disappears when printing a table in Excel? 1. Open a file that needs to be printed, as shown in the figure below. 2. Select all required content areas, as shown in the figure below. 3. Right-click the mouse and select the "Format Cells" option, as shown in the figure below. 4. Click the “Border” option at the top of the window, as shown in the figure below. 5. Select the thin solid line pattern in the line style on the left, as shown in the figure below. 6. Select "Outer Border"

Excel is often used to process data in daily office work, and it is often necessary to use the "filter" function. When we choose to perform "filtering" in Excel, we can only filter up to two conditions for the same column. So, do you know how to filter more than 3 keywords at the same time in Excel? Next, let me demonstrate it to you. The first method is to gradually add the conditions to the filter. If you want to filter out three qualifying details at the same time, you first need to filter out one of them step by step. At the beginning, you can first filter out employees with the surname "Wang" based on the conditions. Then click [OK], and then check [Add current selection to filter] in the filter results. The steps are as follows. Similarly, perform filtering separately again

In our daily work and study, we copy Excel files from others, open them to add content or re-edit them, and then save them. Sometimes a compatibility check dialog box will appear, which is very troublesome. I don’t know Excel software. , can it be changed to normal mode? So below, the editor will bring you detailed steps to solve this problem, let us learn together. Finally, be sure to remember to save it. 1. Open a worksheet and display an additional compatibility mode in the name of the worksheet, as shown in the figure. 2. In this worksheet, after modifying the content and saving it, the dialog box of the compatibility checker always pops up. It is very troublesome to see this page, as shown in the figure. 3. Click the Office button, click Save As, and then

eWe often use Excel to make some data tables and the like. Sometimes when entering parameter values, we need to superscript or subscript a certain number. For example, mathematical formulas are often used. So how do you type the subscript in Excel? ?Let’s take a look at the detailed steps: 1. Superscript method: 1. First, enter a3 (3 is superscript) in Excel. 2. Select the number "3", right-click and select "Format Cells". 3. Click "Superscript" and then "OK". 4. Look, the effect is like this. 2. Subscript method: 1. Similar to the superscript setting method, enter "ln310" (3 is the subscript) in the cell, select the number "3", right-click and select "Format Cells". 2. Check "Subscript" and click "OK"

When processing data, sometimes we encounter data that contains various symbols such as multiples, temperatures, etc. Do you know how to set superscripts in Excel? When we use Excel to process data, if we do not set superscripts, it will make it more troublesome to enter a lot of our data. Today, the editor will bring you the specific setting method of excel superscript. 1. First, let us open the Microsoft Office Excel document on the desktop and select the text that needs to be modified into superscript, as shown in the figure. 2. Then, right-click and select the "Format Cells" option in the menu that appears after clicking, as shown in the figure. 3. Next, in the “Format Cells” dialog box that pops up automatically

Most users use Excel to process table data. In fact, Excel also has a VBA program. Apart from experts, not many users have used this function. The iif function is often used when writing in VBA. It is actually the same as if The functions of the functions are similar. Let me introduce to you the usage of the iif function. There are iif functions in SQL statements and VBA code in Excel. The iif function is similar to the IF function in the excel worksheet. It performs true and false value judgment and returns different results based on the logically calculated true and false values. IF function usage is (condition, yes, no). IF statement and IIF function in VBA. The former IF statement is a control statement that can execute different statements according to conditions. The latter

In the study of software, we are accustomed to using excel, not only because it is convenient, but also because it can meet a variety of formats needed in actual work, and excel is very flexible to use, and there is a mode that is convenient for reading. Today I brought For everyone: where to set the excel reading mode. 1. Turn on the computer, then open the Excel application and find the target data. 2. There are two ways to set the reading mode in Excel. The first one: In Excel, there are a large number of convenient processing methods distributed in the Excel layout. In the lower right corner of Excel, there is a shortcut to set the reading mode. Find the pattern of the cross mark and click it to enter the reading mode. There is a small three-dimensional mark on the right side of the cross mark.

1. Open the PPT and turn the page to the page where you need to insert the excel icon. Click the Insert tab. 2. Click [Object]. 3. The following dialog box will pop up. 4. Click [Create from file] and click [Browse]. 5. Select the excel table to be inserted. 6. Click OK and the following page will pop up. 7. Check [Show as icon]. 8. Click OK.
