Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate weekly and monthly total in spreadsheet

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.

enter image description here

(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

like image 264
Dejan Marjanović Avatar asked Dec 27 '22 22:12

Dejan Marjanović


2 Answers

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),"")

like image 112
assylias Avatar answered Jan 16 '23 12:01

assylias


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.

like image 35
Ross Larson Avatar answered Jan 16 '23 11:01

Ross Larson