如何对按多个条件过滤的行求和

How to SUM rows filtered by multiple criteria

Google 表格问题。

我有以下 sheet(名为 "x")包含费用:

Date        Sum Category
1/Jan/2017  100 red
2/Jan/2017  200 blue
3/Jan/2017  10  red
4/Jan/2017  20  blue
1/Feb/17    1   red
2/Feb/17    2   blue

我需要计算每个类别的每月总计:

Month   Red Blue
Jan/17  110 220
Feb/17  1   2

我目前的解决方案是在每个结果单元格中放置如下内容:

=SUM(IFERROR(FILTER(x!$B:$B, MONTH(x!$A:$A)=MONTH($A2), x!$C:$C="red")))

请问有没有更好的方法。我想要一个单一的结果公式来处理一个数组(也许是一个 ArrayFormula?!),而不是在每个单元格中放置和自定义我的公式。

有什么想法吗?!谢谢!

好吧,这是使用数据透视表 tables 的基本想法,但还不够,因为到目前为止我只能得到月份的数字

query(A:C,"select month(A)+1,sum(B) where C<>'' group by month(A) pivot C label month(A)+1 'Month Number'")

编辑

可以使用数组公式和 VLOOKUP 将月份编号更改为月份名称,但公式有点长(我的 table 月份编号和名称在列 I 和 J 中)

=arrayformula({vlookup(query(query(A:C,"select month(A)+1,sum(B) where C<>'' group by month(A) pivot C label month(A)+1 'Month Number'"),"select Col1"),I:J,2,false)})

你还需要选择其他两列 - 这就是全部内容

=arrayformula({vlookup(query(query(A:C,"select month(A)+1,sum(B) where C<>'' group by month(A) pivot C label month(A)+1 'Month Number'"),"select Col1"),I:J,2,false),query(query(A:C,"select month(A)+1,sum(B) where C<>'' group by month(A) pivot C label month(A)+1 'Month Number'"),"select Col2,Col3")})