Forum Discussion
Excel
Oct 30, 2020Iron Contributor
Sum in every 7 days
Hello Everyone😊
I want to total in every 7 days with formula. How can i do?
4 Replies
Sort By
- mtarlerSilver Contributor
Excel there are a number of ways to do this. I thought you would also want a companion column to id the week # which also makes the formula easier 🙂
Week # Formula:
=UNIQUE(IFERROR(INT((A:A)/7)+1,1))
Weekly Sum Formula:
=SUMIFS(B:B,A:A,">"&7*(D2#-1),A:A,"<="&7*D2#)
based on the week # formula being in cell D2 as in this layout:
- mtarlerSilver Contributor
the first equation to get week number:
it first divides the day by 7 but since that starts with 0.14... which INT truncates to 0, it adds 1. then because "Day" causes an error the IFERROR just sets that error to 1. Now it has a list of values like 1,1,1,1...2,2,2...etc... but we only want ONE of each so I use the UNIQUE function to return only the unique values.
I just thought of a completely different approach and could have used something like
=SEQUENCE(INT(MAX(A:A)/7))
which finds the max day number, divides by 7 and then SEQUENCE creates a counting from 1 to that number.
the second equation:
SUMIFS() function will sum a series of numbers in the array B:B if the following conditions are met:
a) the corresponding value in A:A is > 7*(D2#-1). where D2# are the set of values returned by the formula in D2 (week #s). so for each week # it subtracts 1, multiplies by 7 and checks if the value in col A is bigger than that (i.e. the day # that corresponds to the end of the prior week)
b) same a condition a) but looking to be <= to the day # that corresponds to the end of that week.
I hope that helps explain it but feel free to ask me more detailed question if there is a part that doesn't make sense. I'm guessing the D2# might be the part that throws you since that is a new concept with these new array formulas. Basically the added # means don't just look at the value in that specific cell but all the values that cell formula returns. It is very useful and powerful to be able to expand across all the data in that column without referencing the whole column and have to address the values (blanks, headers, etc...) that may throw errors.
Also feel free to like and mark the answer as best solution if you like it and it worked for you 🙂