round down difference between two dates

ajm

Well-known Member
Joined
Feb 5, 2003
Messages
2,056
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

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
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,224,820
Messages
6,181,155
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