YTD total at change of year

Heimhenge

New Member
Joined
Apr 16, 2024
Messages
4
Office Version
  1. 2007
Platform
  1. Windows
Greetings All, new to this forum and first post. Been coding Excel formula's for 20 years and this one has me stumped. Coming to the experts for some help. TIA.
Trying to do a YTD total for rainfall. Using this formula:

=IF(N19=0, "",

IF(YEAR(A19)<>YEAR(A18), "",

IF(N19=0, O18,

SUMIFS(N:N,A:A, ">="&DATE(YEAR(A19), 1, 1),A:A, "<="&A19))))

Generates good numbers in most cases. See attachment excel-1.jpg.

Column N is where I enter the weekly rainfall total from my rain gauge. Column O shows the YTD total rainfall.

The glitch occurs when it's the first week of the year AND there is a non-zero rainfall to enter in comun N.

See attachment excel-2.jpg.

I'm thinking I might need an IF/AND expression but can't find the right code. Any help is most appreciated.

-Dan
 

Attachments

  • excel-1.jpg
    excel-1.jpg
    99.9 KB · Views: 18
  • excel-2.jpg
    excel-2.jpg
    184.5 KB · Views: 20

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Maybe this?

Regards

Murray


Book1
ANO
1RainYTD
228/12/202311
329/12/20231
430/12/202334
531/12/20234
61/01/202422
72/01/202457
83/01/20247
91/01/20250
102/01/20250
113/01/202522
Sheet1
Cell Formulas
RangeFormula
O2:O11O2=IF(YEAR(A2)<>YEAR(A1),N2,SUM(O1,N2))
 
Upvote 0
Thanks for the suggestions, but I don't see how to implement them w/o creating additional problems.

myall_blues: I see that works perfectly in your spreadsheet, but don't see where it should go in my existing formula. There are four lines, each addressing some aspect of the YTD calculation. If you're suggesting it to replace the existing second line, the last two lines won't be executed.

footoo: I see the same issue with your suggestion.
 
Upvote 0
It should replace your existing formula entirely.
Wow! You are right. When I tried it I got all the correct numbers, including those at the change of the year (not shown in attached image). Samw with the formula suggested by footoo. Both removed some of my preferred formatting though ... like when there's no rain in column N, I want a blank cell in column O just to reduce visual clutter and not be redundant. I could probably work that out on my own at this point, but you're obviously the experts, so I'll ask how you would do that? TIA!
 

Attachments

  • excel-3.jpg
    excel-3.jpg
    50.2 KB · Views: 15
Upvote 0
Because of the way the running total works I'd suggest that rather than try to blank it out using the formula, you do it with conditional formatting by setting the text colour to white when the corresponding cell in column O is blank. Like so:

Book1
ABNO
1
228/12/202311
329/12/20231
430/12/202334
531/12/20234
61/01/202422
72/01/202457
83/01/20247
91/01/20250
102/01/20250
113/01/202522
Sheet1
Cell Formulas
RangeFormula
O2:O11O2=IF(YEAR(A2)<>YEAR(A1),N2,SUM(O1,N2))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
O2:O11Expression=ISBLANK(N2)textNO


Regards

Murray
 
Upvote 0
Solution
Never used conditional formatting for cells but found another way to get the same result. Since column O now has the correct values, I simply changed it a helper column and hid it. Then I created a new column P for the YTD values and used this formula:

=IF(N19=0,"",O19)

Works perfectly now. Thanks for all the help. I'm gonna mark your equivalent solution as the answer to my question.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top