round down difference between two dates

ajm

Well-known Member
Joined
Feb 5, 2003
Messages
2,007
Office Version
  1. 365
Platform
  1. Windows
hi all,

I am using an Add Column custom column to hold the number of years between the Start Date and today. My start dates are in column "Start Date". Power query formula is:

=Duration.Days(DateTime.Date(DateTime.LocalNow()) - [Start Date])/365

This gives me the duration in decimal years eg 7.29354768, 0.254677894, 9.65473922. To get this to whole numbers, as a next step i can use Round Down from the Transform menu (Rounding>Round Down) which accurately reduces the decimal numbers to whole numbers.

However, if i try to apply the round down function to the duration day formula mentioned above, i get errors.

this calculation forms part of a larger "if" statement so i need to have only one formula in one step.

any suggestions?
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
If you want to round the result of the formula to the nearest whole number, you can use the `ROUND` function. Here's how you can modify your formula to round the result:

`=ROUND(Duration.Days(DateTime.Date(DateTime.LocalNow()) - [Start Date])/365, 0)`

The `, 0` at the end of the `ROUND` function specifies that you want to round to 0 decimal places, which means rounding to the nearest whole number.

This formula will give you the rounded number of years between the current date and the `[Start Date]`.
 
  • Like
Reactions: ajm
Upvote 0
Solution
this is what i ended up with:

Number.RoundDown(Duration.TotalDays(Date.From(DateTime.LocalNow()) - [Start Date])/365.25)+1)*12

we times by 12 to bring the answer back to years for use in Edate formula.

i think Usman's answer above is easier to understand though.
 
Upvote 0

Forum statistics

Threads
1,215,103
Messages
6,123,105
Members
449,096
Latest member
provoking

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