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
bamak35
New Member

Calculate Duration between two rows based on a group

Hello! I am really new to Power BI and I think that this problem may be straightforward and it honestly would be much easier for me in my programming background but I am having trouble wrapping my head around it in Power BI. 

 

What I am trying to accomplish is calculating duration averages based on a job-process-task hierarchy. This data is logging data that contains Start and End times for both tasks and processes, there is no specific table for job logging data. Here is an example of how the data model is laid out:

  • JobId
    • ProcessId
      • TaskId
      • TaskId
    • ProcessId
      • TaskId
  • JobId
    • ProcessId...

I think you get the picture. I have Task tables that contain the logging information for each task of a specific process. I also have a process table that contains logging information for each process of a job. In a specific task table, it logs each task with its corresponding ProcessId and each task has a start and end time. I have the duration of each task but when I take an average of this column I am getting the average duration of a singular task as opposed to how long the entire process takes. For example, if ProcessId 1 contains 4 tasks that each take 3 minutes to complete - the duration of this instance ProcessId 1 is 12 minutes - but the average will come out as 3 minutes. 

 

What I need is some way to take the earliest start time and the latest end time and find that difference. In general, the formula would be something like: Average(DateDiff(Min(StartTime),Max(EndTime)) GROUPED BY ProcessId. The logic follows for calculating the average duration of jobs as well where a job may contain various processes so the duration of the job is the difference between the start time of the first process and the end time of the last process. 

 

I am want to create a measure for this calculation that will allow me to add additional filters to this as well i.e. calculate this same average for the last 7 or 30 days - which is straightforward enough using DATESINPERIOD. But this initial average calculation is throwing me off.

 

I would greatly appreciate any feedback or advice and also please feel free to ask any clarifying questions if something isn't explained well enough!

 

Thank you in advance!

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

Perhaps: https://community.powerbi.com/t5/Quick-Measures-Gallery/Lookup-Min-Max/td-p/985814

 

Or maybe See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

Hi @bamak35,

Can you please share some dummy data with the expected result to help us clarify your requirement and test to coding formula?

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Greg_Deckler
Super User
Super User

Perhaps: https://community.powerbi.com/t5/Quick-Measures-Gallery/Lookup-Min-Max/td-p/985814

 

Or maybe See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.