admin管理员组文章数量:1287580
I have a sheet which contains monthly amounts which occasionally need to be adjusted for various reasons. Currently I'm adding rows beneath the month for adjustments and then manually referencing the added adjustment rows for the SUM in the Adjustments cell for the month's row. For example, C5 contains a manually written formula =SUM(D6:D7)
which references the two adjustment rows with values in D6 and D7.
Ideally I'd like to be able to just have a single formula for the whole C column that automatically sums all of the rows beneath it which have the word "Adjustment" in the B column up until the next normal month row, but I can't find a good way to perform a SUM that stops when the condition (the cell in column B matching "Adjustment") is no longer true. Am I missing an obvious way to do this with a formula? Is there a better way to structure this?
I could of course use Adjustment columns, but the number is variable so I would need a number of additional columns proportional to the maximum number of Adjustments which is annoying.
Example Sheet
1 | Month (A) | Amount (B) | Adjustments (C) | Total (D) |
---|---|---|---|---|
2 | January | 100 | =SUM(B2:C2) (100) |
|
3 | February | 150 | =SUM(D4) (-50) |
100 |
4 | Adjustment | Just Because | -50 | |
5 | March | 100 | =SUM(D6:D7) (-100) |
0 |
6 | Adjustment | One! | 100 | |
7 | Adjustment | Two! | -200 | |
8 | April | 0 |
I have a sheet which contains monthly amounts which occasionally need to be adjusted for various reasons. Currently I'm adding rows beneath the month for adjustments and then manually referencing the added adjustment rows for the SUM in the Adjustments cell for the month's row. For example, C5 contains a manually written formula =SUM(D6:D7)
which references the two adjustment rows with values in D6 and D7.
Ideally I'd like to be able to just have a single formula for the whole C column that automatically sums all of the rows beneath it which have the word "Adjustment" in the B column up until the next normal month row, but I can't find a good way to perform a SUM that stops when the condition (the cell in column B matching "Adjustment") is no longer true. Am I missing an obvious way to do this with a formula? Is there a better way to structure this?
I could of course use Adjustment columns, but the number is variable so I would need a number of additional columns proportional to the maximum number of Adjustments which is annoying.
Example Sheet
1 | Month (A) | Amount (B) | Adjustments (C) | Total (D) |
---|---|---|---|---|
2 | January | 100 | =SUM(B2:C2) (100) |
|
3 | February | 150 | =SUM(D4) (-50) |
100 |
4 | Adjustment | Just Because | -50 | |
5 | March | 100 | =SUM(D6:D7) (-100) |
0 |
6 | Adjustment | One! | 100 | |
7 | Adjustment | Two! | -200 | |
8 | April | 0 |
Note: Cells with formulas have the actual value of the cell in parentheses after the formula. The formula for the total column was autofilled from D2 so I only included the formula in D2
Share Improve this question edited Feb 24 at 4:57 Cole asked Feb 23 at 19:33 ColeCole 1386 bronze badges 4- 1 It isn't enough to just show the table. You need to explain the logic required to get the Total in detail. Be specific, and clearly indicate which cells are manually entered and which you need to calculate with a formula. – doubleunary Commented Feb 23 at 21:23
- @doubleunary ahh good point, edited to add the formulas – Cole Commented Feb 23 at 21:54
- @Cole Still question is unclear? Can you please put a screenshot of your sample data so that we can see actual scenario? Also which column is your desired output? Column C or column D? – Harun24hr Commented Feb 24 at 2:16
- Hmm I see my wording was pretty vague now. I'm specifically looking for formulas for the C column. The D column is just a total that uses the C column and B column. I updated the question and included a link to the example sheet – Cole Commented Feb 24 at 5:00
1 Answer
Reset to default 3I have done this before as follows
Add a column between A and B set B2 to equal "=if(A2="",B1,A2)" Fill down and hide the column.
In what is now E2 (Total) the following formula should work "=SUMIFS(E2:E15,B2:B15,A2,C2:C15,"Adjustment")"
I get the following --removed for violating best practice rules--
I hope this helps
本文标签: Google Sheets SUM until a condition failsStack Overflow
版权声明:本文标题:Google Sheets SUM until a condition fails - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741305286a2371331.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论