YearFrac and Leap Year.

Highworld

New Member
Joined
Jan 31, 2023
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Hello,

Was looking for some help on this situation. I am trying to see if there would be a better way for this formula as it is causing issues during leap years.

1710275487764.png


the Yearfrac is pulling from the following details.

1710275527001.png


I would be open to changing the formula to work with leapyears going forward but not sure how about to go with that situation.
 
That is neither a table or a mini xl2bb worksheet? Are there any formulas in this?
I think i got this working.

Book2 (3).xlsx
G
84.793103
Sheet1
Cell Formulas
RangeFormula
G8G8=IF(G1=TRUE,LET(ptMths, DATEDIF(I5, I6, "m"), ptDays,I6-EDATE(I5,ptMths),ptMths+(ptDays/DAY(EOMONTH(I6,0)))),IF(D2=TRUE,(G2*12)+(I1-1)+(I2/G3),G2*12))




4.793103
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
it is helpful, but you need to select the entire range of cells that are part of the formula. You just pasted one cell.
 
Upvote 0
it is helpful, but you need to select the entire range of cells that are part of the formula. You just pasted one cell.


That was my bad. did not highlight the area.


Book2 (3).xlsx
DEFGHI
1YTD20232022TRUEMonth2
2FALSEFALSEFALSE0Day10
3$4,197.88$10,546.25TRUEYear2021
4TRUE
5505Start Date09/18/23
6505Paid Thru02/10/24
7
8$4,197.88$0.00$0.004.793103
9$875.82TRUE
10TRUE
11$875.82
12
Sheet1
Cell Formulas
RangeFormula
F1F1=E1-1
G2G2=COUNTIF(E2:F2, TRUE)
G3G3=IF(OR(I1=4,I1=6,I1=9,I1=11),30,IF(I1=2,G4,31))
G5G5=ROUND(I3/4,0)
G6G6=I3/4
D8D8=IF(AND(D2=TRUE,I1<>"",I2<>""),SUM(D3:D7),IF(AND(G1=TRUE,I5<>"",I6<>""),SUM(D3:D7),0))
E8:F8E8=IF(E2=TRUE,SUM(E3:E7),0)
G8G8=IF(G1=TRUE,LET(ptMths, DATEDIF(I5, I6, "m"), ptDays,I6-EDATE(I5,ptMths),ptMths+(ptDays/DAY(EOMONTH(I6,0)))),IF(D2=TRUE,(G2*12)+(I1-1)+(I2/G3),G2*12))
D9D9=ROUND(IF(G8=0,0,SUM(D8:F8)/G8),2)
D11D11=D9
Cells with Conditional Formatting
CellConditionCell FormatStop If True
F2Expression=$F$10textNO
E2Expression=$E$10textNO
D2Expression=$D$10textNO
D2Expression=$D$10=TRUEtextNO
E2Expression=$E$10=TRUEtextNO
F2Expression=$F$10=TRUEtextNO
H1:H3,D8Expression=$O$9=$P$9textNO
H5:I6Expression=IF($G$9=FALSE,TRUE,FALSE)textNO
H1:I3Expression=IF($G$9=TRUE,TRUE,FALSE)textNO
Cells with Data Validation
CellAllowCriteria
I1Whole numberbetween 1 and 12
I2Whole numberbetween 1 and 31
I3Whole numberbetween 2010 and 2030
 
Upvote 0
Thanks, and please tell the forum what it is you are trying to calculate? An average of something?
Why are you entering a date in 3 different cells?
 
Upvote 0
Thank you for the help at this point.

What i am trying to get is where the numbers circled in red will help feed into the average circled in Green. For example, calculating the long way would take way too long for the number of times being done in one day. By doing the formula by hand it would come out to 4.77 (rounded). the 4.793103 is currently not calculated in the extra day for the leap year. I am not sure if there is a way to get that to show into the average, as this is causing some errors in data.

1710537458056.png
 
Upvote 0
what does the value in G8 mean? Is it the average dollars per day from start date to thru date on the different between one year to the next?
I'm not a financial planner so please tell me what you want the calculation to do? if there are conditions that is fine.
 
Upvote 0
So if you provide @awhoohaw with the details he is asking for he can probably provide you more complete response.
For the days calculation, you need to provide the exact steps you take to do the manual calculation including whether you want to include the start and end date or only the end date and what month you are using as the divisor for the fraction of a month calculation.

Your date range does not cross over the end of Feb so the use of the leapyear is only as a divisor for the fraction assuming you use Feb as the base.
The formula I gave you does not include the start day and uses 29 days for Feb as the divisor.
I think you are using 30 days as the divisor (this is the only way I can come up with your number). This means Leap Year does not even factor into this particular example.

1710541015773.png


If you want the divisor to always be 30 then it simplifies the formula down to.

Excel Formula:
=LET(ptMths,DATEDIF(I7,I8,"m"),
ptDays,I8-EDATE(I7,ptMths),
ptMths+(ptDays/30))
 
Upvote 0
So if you provide @awhoohaw with the details he is asking for he can probably provide you more complete response.
For the days calculation, you need to provide the exact steps you take to do the manual calculation including whether you want to include the start and end date or only the end date and what month you are using as the divisor for the fraction of a month calculation.

Your date range does not cross over the end of Feb so the use of the leapyear is only as a divisor for the fraction assuming you use Feb as the base.
The formula I gave you does not include the start day and uses 29 days for Feb as the divisor.
I think you are using 30 days as the divisor (this is the only way I can come up with your number). This means Leap Year does not even factor into this particular example.

View attachment 108455

If you want the divisor to always be 30 then it simplifies the formula down to.

Excel Formula:
=LET(ptMths,DATEDIF(I7,I8,"m"),
ptDays,I8-EDATE(I7,ptMths),
ptMths+(ptDays/30))

@Alex Blakenburg , i think you have it figured out much more than me. But, @Highworld , if you can add anything that can help us get to your solution it would be great.
 
Upvote 0

Forum statistics

Threads
1,215,217
Messages
6,123,675
Members
449,116
Latest member
HypnoFant

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