What I'd like is to have a fill down formula that looks to see when the date value changes, and sum all the previous rows for that specific date.
For example, here's a spreadsheet:
In column J, you'll see that those values are the sums of each day. Those sums should only be displayed when the date changes, and the sums will just be the sums of each specific day. I think this has to require an array formula of some kind, but any suggestions? Thanks!
UPDATE @Scott
I should mention that the dates aren't always the same length, meaning there could have been 2 rows on one date, and 6 on another date. They are sorted, but different number of rows. So it needs to also look backwards to see where the dates change as well...
I've used the formula provided in column K, and then filled it down. The expected answer is in the column just to the right of that.
CodePudding user response:
Moving my comment to an answer because I believe this works, assuming your data is sorted by date, as Scott notes:
=IF(B2<>B3, SUMIF(B:B, B2, I:I), "")
This says if the next date is not equal to the current date, sum all values for that date. Otherwise leave the cell blank.
Edit: just noting for clarity based on the comments, the formula with the given row references assumes the table in question has a 1 row header, and the formula is written in row 2 and filled down. For this question the formula goes in J2
and is filled down. Also note that if you choose to reference a specific cell range instead of entire columns with B:B
and I:I
, the row references need to be anchored so they don't move when filled down, for example: =IF(B2<>B3, SUMIF(B$1:B$100, B2, I$1:I$100), "")
CodePudding user response:
Update @OP was looking for a forumla based approach.
Well, if the dates are sorted then it can be done with following formula in row 2 beside the Net Units column.
=IF(B2<>B3, SUMIF ($B$2:$I$50, B2, $I$2:$I$50), "")
The row numbers and columns letter should be changed to reflect the data to be selected. Missing the $ (absolute reference) will break the formula.
sumif (range, criteria, sum_range)
// Range is you area from criteria column till the sum_range column, and sum_range is the column that has numerical value to be added.
This kind of problem is best solved by using Pivot Tables. Select your data, make sure each column name/field is unique and then proceed as follows:
- Go to Menu > Insert > Pivot Table
- Select the cells or worksheet (new worksheet preferred) where you want the Pivot Table to be created.
- In the PivotTable builder select, your Date column to Rows
- Select the columns that you want to be summed up and drag to the Values Filed
- Adjust the Value Filed Settings (in the Values Field list (click the drop down arrow next to each field) to SUM function. [if needed]
Viola! This should produce the desired outcome and should be the preferred method.