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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

Find average duration between two dates

Hello,

 

I am working with some IT Incident Data and we are looking to get a field created for the average time between the tickets created date and resolved date. I have done some research and I have a few steps done but I'm having trouble with the actual averaging part.

 

We have "Created On" and "ResolvedDateTime". I was able to find a formula online to find the date difference between the two

 

if [ResolvedDateTime] is null then Duration.Days(DateTime.LocalNow()-[Created On]) else Duration.Days([ResolvedDateTime]-[Created On])

 

This works great. It shows a whole number difference between the two dates. Ideally I would like to get the difference down to days, hours, and minutes but that can wait. Now I'm trying to find the average amount of time from this new 'Date Difference" column. I did some additional research and found a similar post on this forum and I think I am close.

 

Average Open Duration = AVERAGE(Data[Date Difference])
 
I think this would technically work, but the model we are using has incidents that do not have resolution yet, therefore the ResolvedDateTime field is blank, and because of that I'm getting the below error.
 
rober136_0-1703180488917.png

 

Any ideas on how I can get either my formula to change the zeros, or get a similar 2nd formula that knows what to do with the zeros? In a similar vein, I would like the "Date Difference" to show Days, Hours, and Minutes if possible. Not entirely sure how much that changes the formula but wanted to include that just in case.

 

1 REPLY 1
gmsamborn
Super User
Super User

Hi @Anonymous 

 

I'm not sure why that custom column didn't work.  Instead I created a column using your IF logic and then calculated days based on that date.

 

 

let
    Source = Excel.Workbook(File.Contents("C:\Power_BI\PBI Community\Find average duration between two dates\SampleData.xlsx"), null, true),
    Tickets_Sheet = Source{[Item="Tickets",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Tickets_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"TicketID", Int64.Type}, {"Created On", type date}, {"x", Int64.Type}, {"ResolvedDateTime", type date}, {"Other field", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"x"}),
    #"Added Custom" = Table.AddColumn(#"Removed Columns", "Custom", each if [ResolvedDateTime] = null then DateTime.LocalNow() else [ResolvedDateTime]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", type date}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type1", "Days", each Duration.Days( [Custom] - [Created On] )),
    #"Changed Type2" = Table.TransformColumnTypes(#"Added Custom1",{{"Days", Int64.Type}}),
    #"Removed Columns1" = Table.RemoveColumns(#"Changed Type2",{"Custom"})
in
    #"Removed Columns1"

 

 

Ignore anything above #"Added Custom".

Let me know if you have any questions.



Proud to be a Super User!

daxformatter.com makes life EASIER!

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.