简体   繁体   English

Excel / Google表格中基于条件的总和行

[英]Sum row in Excel/Google Sheets based on Condition

It seems like this question should exist somewhere, but I can't seem to find it...exactly. 似乎这个问题应该存在于某个地方,但我似乎找不到……确切。

The most similar solution I can find requires the use of SUMIFS or SUMIF , which only seems to add up numbers in a column, not spanning multiple columns. 我能找到的最相似的解决方案需要使用SUMIFSSUMIF ,这似乎只在一个列中加起来,而不跨越多个列。 Here's an example sheet with 2 rows: 这是一个包含两行的示例工作表:

      A             B    C    D    E    F    G    H  ...
1     2015-01-01    0    1    6   12   45   12    5  ...
2     2016-01-01    256 43   13   35  134  135   12  ...

Now I'd like to have a cell somewhere that adds all of the cells in the row for 2015-01-01 . 现在,我想在某个位置添加一个单元格,以添加该行中所有2015-01-01的单元格。 My attempt looks like: 我的尝试看起来像:

SUMIF(A1:A30,"2015-01-01", B1:BJ30)

But this only yields the sum of the column B, so 0 for the exact formula above or 256 if I were to do this for the year 2016 . 但这只会产生B列的总和,因此对于上面的精确公式为0 ,如果我要在2016这样做则为256

When trying something with SUMIFS , I'm told that the criterion range's size should match the sum range size, which isn't the case because my criterion range is only the first column of dates. 当尝试使用SUMIFS ,系统会告诉我标准范围的大小应与总和范围大小匹配,而事实并非如此,因为我的标准范围只是日期的第一列。

How can I add all the values in a row if the first cell's date matches my criterion? 如果第一个单元格的日期与我的条件匹配,如何连续添加所有值? It may be worthwhile to note that this is in Google Sheets, not Excel. 可能值得注意的是,这是在Google表格中,而不是Excel中。

在excel和googlesheets中,您都可以使用SUMPRODUCT ,例如:

=SUMPRODUCT((A1:A30 = DATE(2015, 1, 1)) * B1:BJ30)

You can try either of these: 您可以尝试以下任一方法:

=if(A1=date(2015,1,1),sum(B1:F1),"")

=if(A1=A1,sum(B1:F1),"")

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

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