Hi all,
I am having the Period End Date as well as the Expiry date of certain contracts. I now want to calculate the difference between Expiry date and Period end date in Years. I have tried the following formula:
(DateTimeDiff([Expiry date],[PeriodDate],"days"))/365
If the result is negative, this means the contract is overdue, if it is positive i want to group it into maturity buckets.
Everything is working as intended except for the leap years. Due to those, the calculation of DateTimeDiff/365 does often not give me the correct numbers. When calculating the time difference between 31/12/2020 and 31/12/2019 I would actually have to divide by 366 since there is an additional day in February.
Is there a way to design this flexibly, even for longer time periods? Please see my formulas and my time buckets down below:
I have already tried things like using 1.00247 instead of 1 in the AgeBucket calclulation, but that will of course falsify the buckets in a non-leap year.
Thank you very much for your help!
Kind regards,
Alex
Solved! Go to Solution.
You can use 'year' as a unit in the datetimediff function. Is there a reason you're doing by days and then doing the division?
I believe it accounts for the leap day accordingly.
My approach would start with making the static value of 365 more dynamic by using the DateTimeDiff() function.
This screenshot demonstrates the ability to dynamically change the value of 365 to 366 for a leap year (if the dates used come from a field).
Let me know if this is at all helpful.
Hi all,
thank you so much for your quick help and the ideas! Sadly the DateTimeDiff for years does not show decimals, which is a shame.
@RolandSchubert This is a great idea, thank you so much! I just made minor changes with regards to the ">=" to adjust for my cause.
That is a an awesome solution, have a great day!
IF DateTimeDiff([PeriodDate], [Expiry date], 'days') >= 0 THEN IF DateTimeDiff(DateTimeAdd([PeriodDate], -1, 'years'), [Expiry date], 'days') < 0 THEN 'Overdue<1Y' ELSE 'Overdue>1Y' ENDIF ELSE IF DateTimeDiff(DateTimeAdd([PeriodDate], 1, 'years'), [Expiry date], 'days') >= 0 THEN 'Maturity<1Y' ELSEIF DateTimeDiff(DateTimeAdd([PeriodDate], 2, 'years'), [Expiry date], 'days') >= 0 THEN 'Maturity<2Y' ELSEIF DateTimeDiff(DateTimeAdd([PeriodDate], 5, 'years'), [Expiry date], 'days') >= 0 THEN 'Maturity<5Y' ELSEIF DateTimeDiff(DateTimeAdd([PeriodDate], 10, 'years'), [Expiry date], 'days') >= 0 THEN 'Maturity<10Y' ELSEIF DateTimeDiff(DateTimeAdd([PeriodDate], 25, 'years'), [Expiry date], 'days') >= 0 THEN 'Maturity<25Y' ELSE 'Maturity>25Y' ENDIF ENDIF |