如何根据Google表格中的下拉范围计算总计?

时间:2017-06-09 07:20:24

标签: google-sheets

这是我的表:

Item | Person | Price
Shoes | John | $25
Clothes | John | $25
Pants | John | $50
Bags | Sarah | $50
Watch | Sarah | $150
Aftershave | John | $15

我已经设法将Person表作为教程后的下拉列表。

我知道想要另一个名为totals的列,它将根据用户计算总数:

Total Sarah:
Total John:

例如,它应该动态查找所有Sarah并更新总数。我尝试过使用sumif,但如果所选列中的所有行都与总数

匹配,我怎么能sumif

这是我的样本表:

https://docs.google.com/spreadsheets/d/13MwyK-Suvvg9LfvzFcW-ojL9ilvb5OKCFjQwXgI4h70/edit?usp=sharing

我也试过

=query(sum(B:B,"count * where B ='John'" ,-1))

=sum(query(B:B, "select B where B='John'")+query(C:C, "select B,C where B='John'"))

2 个答案:

答案 0 :(得分:1)

请清除列F:G和F1:

=query(A2:C30,"select B, sum(C) group by B")

在G9:=sum(G2:G6)和格式适合。

答案 1 :(得分:1)

仅适用于Google表格:

={QUERY({A:C},"select Col2, sum(Col3) where Col2 <> '' group by Col2");"Total",SUM(C:C)}

工作原理

  1. 使用数组{}将范围A:C转换为数组{A:C}。这是为了在Col1, Col2...中使用query表示法。我更喜欢这个,因为范围字母A, B, C可能会改变蚂蚁,这会导致公式崩溃。
  2. 使用查询来获得总和。这里是the reference
  3. 使用数组{array; value,calue}来组合公式。这是link to documentation