[英]Using Google Sheets, how can I calculate the average per month based on multiple rows?
I have a spreadsheet where I am entering Groceries on each row every time I visit a store. 我有一个电子表格,我每次访问商店时都会在每行输入Groceries。 I have calculated the overall sum, but now I would like to calculate the average cost per month for the groceries. 我已计算出总额,但现在我想计算杂货的每月平均成本。
I don't even know where to begin on this. 我甚至不知道从哪里开始。 I have posted my spreadsheet ( https://docs.google.com/spreadsheets/d/1R0zYMAigDULzm8oM2icsPK55BP162kVvctpx2cOSOIE/edit?usp=sharing ). 我已发布电子表格( https://docs.google.com/spreadsheets/d/1R0zYMAigDULzm8oM2icsPK55BP162kVvctpx2cOSOIE/edit?usp=sharing )。
Try this in B5. 在B5中尝试这个。 It will take the year and month into account (so 1/7/2018 will count as a separate month from 1/7/2017). 这将需要考虑年份和月份(因此1/17/2018将被视为从2017年1月7日起的单独月份)。 It counts unique year-month combinations and divides the sum spent. 它计算独特的年 - 月组合并划分花费的总和。 The minus one accounts for the blank cell counted as unique. 减号计算空白单元计为唯一。
=sum(B9:B)/arrayformula(countunique(text(A9:A,"YYYY-MM"))-1)
same answer, using double query: 相同的答案,使用双重查询:
=QUERY( QUERY({A8:B}, "select year(Col1), month(Col1), sum(Col2) group by year(Col1), month(Col1)"), "select avg(Col3) label avg(Col3) ''")
The inside query is report with sums by years and months: 内部查询是按年和月的总和报告:
formula: 式:
=QUERY({A8:B}, "select year(Col1), month(Col1), sum(Col2) group by year(Col1), month(Col1)")
result: 结果:
year(Date) month(Date) sum Amount
2016 10 133.00
2017 0 80.00
2017 1 420.00
Months are zero-based: 0 - Jan, 2 - Feb... 月份为零:0 - 1月2日 - 2月......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.