简体   繁体   English

在电子表格中查找每一行的总和

[英]Find the sum of each row in a spreadsheet

I'm new to Sheets and I don't know any terminology yet so I wasn't sure how to look this up. 我是Sheets的新手,我还不知道任何术语,所以我不确定该如何查找。 If I have: 如果我有:

A1[=SUM(B1:1)]

How do I automatically copy that to A2 so that: 如何自动将其复制到A2,以便:

A2[=SUM(B2:2)]

And the same thing continues either indefinitely or until I declare a stopping point? 同样的事情会无限期地持续下去,或者直到我声明一个停止点为止?

First of all, if you simply copy-paste the formula from A1 to A2 (or several cells below), it will automatically change as you want. 首先,如果您只是简单地将公式从A1复制粘贴到A2(或下面的几个单元格),它将根据需要自动更改。 This is how relative references work. 这就是相对引用的工作方式。

But it's also possible to get all the sums with one formula. 但是也可以用一个公式来获得所有和。 The following formula, entered in A1, will create sums of the first seven row in column A. To change the number of rows summed, replace 7 in B1:7 with another number. 在A1中输入的以下公式将创建A列中前7行的总和。要更改总行数,请用另一个数字替换B1:7

=arrayformula(mmult(B1:7 + 0, transpose(B1:1 * 0 + 1)))

Explanation: 说明:

  • B1:7 + 0 coerces the entries to numbers (so that blank cells become 0). B1:7 + 0将条目强制为数字(以使空白单元格变为0)。
  • transpose(B1:1 * 0 + 1) creates a column vector of 1s of suitable size. transpose(B1:1 * 0 + 1)创建合适大小的1s列向量。
  • matrix multiplication mmult by a column of 1s amounts to summing each row. 矩阵乘法mmult由1组成的列相当于求和每一行。
  • the wrapper arrayformula indicates that the operations are to be done on arrays. wrapper arrayformula表示要对数组执行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM