Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Time between dates using three columns

Hi experts,

 

I have the following data:

 

SophRow_0-1679630347862.png

 

I want to create a calculated column (either in PQ or DAX - whatever is most suitable) to calculate tenure in months based on Last Hire Date. However if the Last Hire Date is after the Termination Date (in a fraction of cases) I want to use the Hire Date column. 

 

The output would look like the red column above. 

 

Any help greatly appreciated!

 

Best,

Soph

1 ACCEPTED SOLUTION
Arul
Super User
Super User

@Anonymous ,

try this DAX formula,

Tenure in Months = 
IF (
    'Table'[Last Hire Date] > 'Table'[Termination Date],
    DATEDIFF ( 'Table'[Hire Date], 'Table'[Termination Date], MONTH ),
    DATEDIFF ( 'Table'[Last Hire Date], 'Table'[Termination Date], MONTH )
)

Arul_0-1679633085868.png

Thanks,

Arul





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


View solution in original post

4 REPLIES 4
grazitti_sapna
Super User
Super User

You can use 

Tenure = SWITCH(TRUE(),Tenure[Last Hire Date]>Tenure[Termination Date],DATEDIFF(Tenure[Hire Data],Tenure[Termination Date],DAY),Tenure[Last Hire Date]<Tenure[Termination Date],DATEDIFF(Tenure[Last Hire Date],Tenure[Termination Date],DAY))

Arul
Super User
Super User

@Anonymous ,

try this DAX formula,

Tenure in Months = 
IF (
    'Table'[Last Hire Date] > 'Table'[Termination Date],
    DATEDIFF ( 'Table'[Hire Date], 'Table'[Termination Date], MONTH ),
    DATEDIFF ( 'Table'[Last Hire Date], 'Table'[Termination Date], MONTH )
)

Arul_0-1679633085868.png

Thanks,

Arul





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


SamInogic
Super User
Super User

Hi @Anonymous ,

As per your requirement, we have created sample table with columns as you mentioned Hire Date, Last Hire Date, Termination Date.


Please refer to the below screenshot,

Sample Date Table.png

For calculating Tenure in Months you can create a new Column with below DAX expression,

Tenure = If('Hire Table'[Last Hire Date].[Date]> 'Hire Table'[Termination Date].[Date],DATEDIFF('Hire Table'[Hire Date].[Date],'Hire Table'[Termination Date].[Date],MONTH), DATEDIFF('Hire Table'[Last Hire Date].[Date],'Hire Table'[Termination Date].[Date],MONTH))

 

These will result as below with Tenure in Months:

SamInogic_0-1679632910872.png

 

If this answer helps, please mark it as Accepted Solution so it would help others to find the solution.


Thanks!

Inogic Professional Service Division

An expert technical extension for your techno-functional business needs

Power Platform/Dynamics 365 CRM

Drop an email at crm@inogic.com

Service:  http://www.inogic.com/services/ 

Power Platform/Dynamics 365 CRM Tips and Tricks:  http://www.inogic.com/blog/

Inogic Professional Services: Power Platform/Dynamics 365 CRM
An expert technical extension for your techno-functional business needs
Service: https://www.inogic.com/services/
Tips and Tricks: https://www.inogic.com/blog/
vicky_
Super User
Super User

For DAX:

Tenure = 
var useDate= MAX([LastHireDate], [TerminationDate])

return DATEDIFF([HireDate], useDate, DAY)

It will be something very similar in PowerQuery, but unfortunately I'm less familiar with that. Hope that helps!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.