Forum

Convert Years/Days ...
 
Notifications
Clear all

Convert Years/Days to Months

6 Posts
3 Users
0 Reactions
330 Views
(@tykru)
Posts: 34
Eminent Member
Topic starter
 

My goal is to covert hired dates to months with the company. I used the PQ to transform the date to age, then transformed the age to years using the Duration button, however, there is no months option in the dropdown, only total years, days, hours etc. Is there a way to transform to total months using the options in the transform ribbon or does this require a custom function using M code?

 

Thanks!

 
Posted : 31/08/2019 8:25 am
(@mynda)
Posts: 4761
Member Admin
 

Hi Tykru,

There's no built in way to calculate it but this post offers a solution. However, it is simpler to do this calculation in Power Pivot using the DATEDIF function.

Mynda

 
Posted : 01/09/2019 2:32 am
(@catalinb)
Posts: 1937
Member Admin
 

Hi,

If you have the age in years, adding a column that multiplies the age by 12 should be enough, normally the age in years should have decimals, so 3.25 years*12 = 39 months for example.

 
Posted : 01/09/2019 3:41 am
(@tykru)
Posts: 34
Eminent Member
Topic starter
 

Awesome, I will take a look at both and see what works for me. I considered using DAX in Power Pivot but am only working from one table so I didn't add to PP data model because how simplistic my solution is. Can you use PP to create measures with only one table?

 

Thanks!

 
Posted : 01/09/2019 4:38 pm
(@mynda)
Posts: 4761
Member Admin
 

Yes, DAX measures can be written for one table.

 
Posted : 01/09/2019 7:15 pm
(@tykru)
Posts: 34
Eminent Member
Topic starter
 

I've tried both Catalin's and your suggestion and they work great. However, when I round both 1 decimal place, the DAX version will round way up (i.e. the M code result will be 11.2 and the DAX will round up to 12.0). Any idea why? 

 

Thanks,

Tyler

 
Posted : 02/09/2019 9:32 pm
Share: