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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

Aggregate rows then calculate duration

Hi all, my data model along with connecting columns are as shown below. Attached is the pbi file.

link to file 

 

connection diagram power bi.PNG

 

Each row in operation_list represents a manufacturing process (also called operation) completed on a given order. Below shows truncated table with two orders on it.

 

power bi operation list.PNG

 

routing_master is the "blueprint" for each order operations on operation_list. Below shown reference for order 121817560 from above. See routing_master[Opseq] column, operation that belong to the same "group" are assigned with the same number e.g., operation 900 to 1500 assigned with Opseq 4.

routing master example.PNG

 

The aim (which is also my question) is how to calculate the duration of each Opseq by subtracting earliest "Start time" from latest "Finish time" of all operations that belong to the same Opseq, subtract break hours from it, and present its average over the week. In table form the final result should look like below. Break hours are: Day (07:30 to 08:00 and 12:00 to 13:00) and Night shift (19:30 to 20:00 and 00:00 to 01:00)

 

WeekLead time per Opseq (days)
 1234
10.21.21.51.4
21.22.22.52.4
32.23.23.53.4
43.24.24.54.4

 

I don't see how solution from Solved: Calculating Working hours - Microsoft Power BI Community can be implemented since the duration calculation was made as calculated table whereas my case need to aggregate first. I had tried the alternative to merge operation_list with routing_master, group by Opseq, and calculate the duration from there but it just takes so much time when data is refreshed.

 

So help a friend? Appreciate all suggestions!

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Anonymous 
Here is the sample file with the solution https://www.dropbox.com/t/4LqnqA6a1sYn0Jip

Not sure if the is what you actually need. Please have a look and let me know if you have any further queries.

1.png

Duration = 
VAR FirstStart = MIN ( operation_list[Start time] )
VAR LastEnd = MAX ( operation_list[Finish time] )
VAR Duration = DIVIDE ( DATEDIFF ( FirstStart, LastEnd, SECOND ), 86400 )
RETURN
    Duration

View solution in original post

4 REPLIES 4
v-rongtiep-msft
Community Support
Community Support

Hi @Anonymous ,

Does that make sense? If so, kindly mark @tamerj1 's  answer as the solution to close the case please. Thanks in advance.

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

It does and thanks for the reminder! 👍

tamerj1
Super User
Super User

Hi @Anonymous 
Here is the sample file with the solution https://www.dropbox.com/t/4LqnqA6a1sYn0Jip

Not sure if the is what you actually need. Please have a look and let me know if you have any further queries.

1.png

Duration = 
VAR FirstStart = MIN ( operation_list[Start time] )
VAR LastEnd = MAX ( operation_list[Finish time] )
VAR Duration = DIVIDE ( DATEDIFF ( FirstStart, LastEnd, SECOND ), 86400 )
RETURN
    Duration
Anonymous
Not applicable

Hi @tamerj1 , thank you for suggestion and it works as expected!

Pardon me for taking a while to mark this as a solution.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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