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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
pswain
Helper I
Helper I

Calculate Difference Between Two Date/Time Values in a new column

 

 

Hi All,

 

I have 2 column below, I would like to have the diffrence in days hours minutes like 2 days 12 hours 6 minutes... I am new to powerbi, can someone help me to provide me step by step process, I would really appreciate it. Thanks have  a good day.

 

pswain_0-1603124052323.png

 

Regards,

Prasanjit

 

2 ACCEPTED SOLUTIONS
PhilipTreacy
Super User
Super User

Hi @pswain 

In Power Query create a new Conditional Column and subtract Closed Month from Creation Month.

 

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Creation Month", type datetime}, {"Closed Month", type datetime}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Duration", each [Closed Month]-[Creation Month])
in
    #"Added Custom"

 

Sample file : Duration

Phil 


If I answered your question please mark my post as the solution.

If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

DavisBI
Solution Specialist
Solution Specialist

Hi, @pswain ,

 

You just need to copy this to your new calculated column:

 

 

 

DIFF = 
VAR _D = DATEDIFF('YourTable'[Closed Month],'YourTable'[Creation Month],DAY)
VAR _H = DATEDIFF('YourTable'[Closed Month],'YourTable'[Creation Month],HOUR)-_D*24
VAR _M = DATEDIFF('YourTable'[Closed Month],'YourTable'[Creation Month],MINUTE)-_D*24*60-_H*60
RETURN
_D & " days" & _H & " hours" & _M & " minutes"

 

 

 

 Best.

View solution in original post

3 REPLIES 3
DavisBI
Solution Specialist
Solution Specialist

Hi, @pswain ,

 

You just need to copy this to your new calculated column:

 

 

 

DIFF = 
VAR _D = DATEDIFF('YourTable'[Closed Month],'YourTable'[Creation Month],DAY)
VAR _H = DATEDIFF('YourTable'[Closed Month],'YourTable'[Creation Month],HOUR)-_D*24
VAR _M = DATEDIFF('YourTable'[Closed Month],'YourTable'[Creation Month],MINUTE)-_D*24*60-_H*60
RETURN
_D & " days" & _H & " hours" & _M & " minutes"

 

 

 

 Best.

PhilipTreacy
Super User
Super User

Hi @pswain 

In Power Query create a new Conditional Column and subtract Closed Month from Creation Month.

 

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Creation Month", type datetime}, {"Closed Month", type datetime}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Duration", each [Closed Month]-[Creation Month])
in
    #"Added Custom"

 

Sample file : Duration

Phil 


If I answered your question please mark my post as the solution.

If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


manikumar34
Solution Sage
Solution Sage

@pswain , 

 

Use DATEDIFF function to get the required output.

 

Regards, 

Manikumar

 

Appreciate your Kudos. Accept as solution if this is helpful





If this helps, Appreciate your KUDOS!
Did I answer your question? Mark my post as a solution!


Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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