Calculate weekly and monthly total in spreadsheet

百般思念 提交于 2019-12-01 04:25:53

问题


How to calculate weekly sum (sum of last 7 rows printed in 7th row) based on daily values, same question for monthly (based on weekly or daily). I have tried some formulas but they all failed.

(first column is date column, not in image)

P.S. sorry for "too localized" and "not constructive" I just don't know how to ask this differently


回答1:


For the week column, you can add a formula like =IF(WEEKDAY(A8)=7,sum(B2:B8),"") (to put the sum of the week on Sundays.

For the month column: =IF(MONTH(A2)<>MONTH(A2+1),SUM(B$2:B2)-SUMIF(A$2:A2,"<"&DATE(YEAR(A2),MONTH(A2),1),B$2:B2),"")




回答2:


For weekly column

=IF(IFERROR(WEEKNUM(A2)=WEEKNUM(A1), FALSE), "",SUM(B2:B8))

for monthly column

=IF(IFERROR(MONTH(A2)=MONTH(A1), FALSE), "",SUMIF(A2:A33, "<"&DATE(YEAR(A2),MONTH(A2)+1,1), B2:B33))

these should work anywhere. Week & month sums will be listed on first day of week/month (what your sheet seemed to have)

Note: the ranges in sumif are 31 days long. I realize every month isnt 31 days. But they are AT MOST 31 days, and each day will only be included if it's month is correct, so it holds for 28,29, and 30 day months as well. This means the formula WILL work for all months without modification.



来源:https://stackoverflow.com/questions/11141966/calculate-weekly-and-monthly-total-in-spreadsheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!