cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
im_newbie_123 Frequent Visitor
Frequent Visitor

Create a custom column to get month value

I have two columns (Hire Date and Current Date)

I have to find date difference between the two columns using the formula :

(Current Date - Hire Date)/12 = Tenure (new column) 

 

Example :

Current Date 

10/23/2019

 

Hire Date 

10/23/2018

 

Tenure

1.0

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Create a custom column to get month value

Hi @im_newbie_123 ,

 

To create a custom column as below.

((((Date.Year([Current Date]) - Date.Year([#"Hire Date "]))-1)*12)+(12-Date.Month([#"Hire Date "]))+(Date.Month([Current Date])))/12

Also we can make it dynamicly by using DateTime.LocalNow().

((((Date.Year(DateTime.LocalNow()) - Date.Year([#"Hire Date "]))-1)*12)+(12-Date.Month([#"Hire Date "]))+(Date.Month(DateTime.LocalNow())))/12

Full code for your reference as well.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwtNQ3NNA3MlHSAXEsoJzYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Current Date" = _t, #"Hire Date " = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Current Date", type date}, {"Hire Date ", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each ((((Date.Year(DateTime.LocalNow()) - Date.Year([#"Hire Date "]))-1)*12)+(12-Date.Month([#"Hire Date "]))+(Date.Month(DateTime.LocalNow())))/12),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each ((((Date.Year([Current Date]) - Date.Year([#"Hire Date "]))-1)*12)+(12-Date.Month([#"Hire Date "]))+(Date.Month([Current Date])))/12)
in
    #"Added Custom1"

full.PNG

 

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

2 REPLIES 2
Nathaniel_C Super Contributor
Super Contributor

Re: Create a custom column to get month value

Hi @im_newbie_123 

 

In Power Query = Table.AddColumn(#"Changed Type", "Custom", each ([Current Date]-[Hire Date])/365)
Go to Power Query, Select Add Column, Custom Column and fill in the code.
Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel
date in m.PNG

 

Community Support Team
Community Support Team

Re: Create a custom column to get month value

Hi @im_newbie_123 ,

 

To create a custom column as below.

((((Date.Year([Current Date]) - Date.Year([#"Hire Date "]))-1)*12)+(12-Date.Month([#"Hire Date "]))+(Date.Month([Current Date])))/12

Also we can make it dynamicly by using DateTime.LocalNow().

((((Date.Year(DateTime.LocalNow()) - Date.Year([#"Hire Date "]))-1)*12)+(12-Date.Month([#"Hire Date "]))+(Date.Month(DateTime.LocalNow())))/12

Full code for your reference as well.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwtNQ3NNA3MlHSAXEsoJzYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Current Date" = _t, #"Hire Date " = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Current Date", type date}, {"Hire Date ", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each ((((Date.Year(DateTime.LocalNow()) - Date.Year([#"Hire Date "]))-1)*12)+(12-Date.Month([#"Hire Date "]))+(Date.Month(DateTime.LocalNow())))/12),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each ((((Date.Year([Current Date]) - Date.Year([#"Hire Date "]))-1)*12)+(12-Date.Month([#"Hire Date "]))+(Date.Month([Current Date])))/12)
in
    #"Added Custom1"

full.PNG

 

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

Helpful resources

Announcements
New Topics Started Badges Coming

New Topics Started Badges Coming

We're releasing new versions of the badge that everyone's talking about. ;) Check your inbox for notifications.

MBAS 2020

Save the new date (and location)!

Our business applications community is growing—so we needed a different venue, resulting in a new date and location. See you there!

Difinity Conference

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

Top Solution Authors
Top Kudoed Authors (Last 30 Days)