简体   繁体   English

Google 表格中的 SUMIFS 和 ARRAYFORMULA

[英]SUMIFS and ARRAYFORMULA within Google Sheets

I have a google sheet with multiple tabs, one of the tabs is for holding each observation of data while another needs to combine data based on certain criteria.我有一个带有多个选项卡的谷歌表,其中一个选项卡用于保存对数据的每个观察结果,而另一个选项卡需要根据特定标准组合数据。 I am trying to use a SUMIFS within and ARRAYFORMULA to get the correct information and it will only pull "0" no matter what I try.我正在尝试使用 SUMIFS 和 ARRAYFORMULA 来获取正确的信息,无论我尝试什么,它都只会拉“0”。

I have set up a test google sheet with some dummy information to show an example of what I need to do in a more complex situation.我已经设置了一个带有一些虚拟信息的测试 google 表,以显示在更复杂的情况下我需要做什么的示例。

https://docs.google.com/spreadsheets/d/1JLyEuVijQ8MvfOKrtbRD_YKmRDnTCxf7qCSw9Ggty_Y/edit#gid=1250575550 https://docs.google.com/spreadsheets/d/1JLyEuVijQ8MvfOKrtbRD_YKmRDnTCxf7qCSw9Ggty_Y/edit#gid=1250575550

In this example, the data tab is the individual observations and the sums tab is where I'm trying to pull combinations.在此示例中,数据选项卡是单个观察值,总和选项卡是我尝试提取组合的位置。 I need column D to sum the totals in column E on the data tab if the Month and Year and Type all match what is on the sums sheet.如果月份和年份和类型都与总和表上的内容匹配,我需要 D 列来汇总数据选项卡上 E 列中的总数。 In this example, cell D3 on the sums tab should equal 11.在此示例中,总和选项卡上的单元格 D3 应等于 11。

It seems QUERY() may be good choice.看来QUERY()可能是不错的选择。 Try-尝试-

=QUERY(data!A2:E,"select A,B,C, sum(E) where A is not null group by A,B,C",1)

If you need specific month then you can add criteria to where clause like-如果您需要特定月份,则可以将条件添加到where子句中,例如-

=QUERY(data!A2:E,"select A,B,C, sum(E) where A =5 group by A,B,C",1)

在此处输入图像描述

you cannot use SUMIFS() in Arrayformula(), along with many other functions, though there is no formal documented list.尽管没有正式的记录列表,但您不能在 Arrayformula() 中使用 SUMIFS() 以及许多其他函数。

In your case you can use a SUMIF() instead by &'ing the condtions together.在您的情况下,您可以通过 &'ing 一起使用 SUMIF() 。

I've demoed the concept on a new tab called MK_Help in cell D2:我在单元格 D2 中名为 MK_Help 的新选项卡上演示了这个概念:

=ARRAYFORMULA(IF(ROW(A2:A) = ROW(A2), "# TOTAL TYPE", IF(A2:A = "", , SUMIF(data!A:A&data!B:B&data!C:C,A2:A&B2:B&C2:C,data!E:E))))

Note that I made a couple of other small changes to your formula.请注意,我对您的公式做了一些其他的小改动。

Namely, that you should always use a true "empty" instead of double quotes in your IF() mask up front tor return empty when there's no value in A. Double quotes("") is actually not quite empty for many other things in Google sheets.也就是说,当 A 中没有值时,您应该始终在 IF() 掩码中使用真正的“空”而不是双引号,否则当 A 中没有值时返回空。对于中的许多其他内容,双引号(“”)实际上并不是空谷歌表。

Also I modified your header conndition from ROW(A2:A)=2 to ROW(A2:A) = ROW(A2) .此外,我将您的 header 条件从ROW(A2:A)=2修改为ROW(A2:A) = ROW(A2) I find that this is a more flexible condition for the header as it allows you to potentially insert/delete rows above the header without breaking things.我发现这对于 header 来说是一个更灵活的条件,因为它允许您在 header 上方插入/删除行而不会破坏任何东西。

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

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