Forum Discussion

Wirestat's avatar
Wirestat
Frequent Visitor
3 years ago
Solved

How to Find Orders Duration based on Start Stop time

Hello, how its possible to find order duration based on starting and finishing time, for example like in column duration. 

Order idFromToDuration
023:0023:03 
130699323:0323:03 
130699323:0323:06 
130699323:2223:33 
130699323:3323:33 
130699323:3423:35 
130699323:3523:37 
130699323:3823:39 
130699323:4223:43 
130699323:4323:4300:40
023:4323:44 
130530023:4423:45 
130530023:4523:46 
130530023:4723:47 
130530023:4823:49 
130530023:5423:54 
130530023:5423:55 
130530023:5623:59 
130530023:5900:00 
130530000:0000:01 
130530000:0200:03 
130530000:0300:03 
130530000:0400:04 
130530000:0400:07 
130530000:0700:07 
130530000:0700:08 
130530000:0800:0900:25
000:0900:10 
130701200:5300:54 
130701200:5400:55 
130701200:5600:58 
130701201:0201:0500:12
001:0501:05 
130703101:0501:05 
130703101:0601:06 
130703101:1101:11 
130703101:1301:14 
130703101:1901:42 
130703101:4401:45 
130703101:4501:46 
130703101:4601:4600:41
  • tamerj1's avatar
    tamerj1
    3 years ago

    Hi Wirestat 
    Please try

    Duration (Minutes) =
    SUMX (
        VALUES ( 'Table'[Order ID] ),
        VAR CurrentIDTable =
            CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[Order ID] ) )
        VAR FirstStart =
            MINX ( CurrentIDTable, 'Table'[From] )
        VAR LastEnd =
            MAXX ( CurrentIDTable, 'Table'[To] )
        RETURN
            DATEDIFF ( FirstStart, LastEnd, MINUTE )
    )

7 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi. 
    Use DateDifference function to achieve the same requirement.

     

     

    Minutes taken = DATEDIFF(tablename[From], tablename[To], MINUTE)

     

     

    Though this will just give the minutes. 

    To achieve the exact requirement, you can follow the Solution mentioned in this below link:
    Solved: datediff in HH:MM format - Microsoft Power BI Community
    OR
    Aggregating Duration/Time - Microsoft Power BI Community

    Thank you.
    If my answer helps you, please mark it as solution.

     

    • Wirestat's avatar
      Wirestat
      Frequent Visitor

      Hi VishalJhaveri, unfortunatly this answer provide diffrance for each row, and my goal is to find duration for complete order. Thank your for affort! 

    • Wirestat's avatar
      Wirestat
      Frequent Visitor

      Hello tamerj1, the gaps shows sub orders serving, just ignore them, the goal to display duration of order from 23:03 until 23:43 which is 40 min time for order 1306993

      • tamerj1's avatar
        tamerj1
        Icon for Community Champion rankCommunity Champion

        Hi Wirestat 
        Please try

        Duration (Minutes) =
        SUMX (
            VALUES ( 'Table'[Order ID] ),
            VAR CurrentIDTable =
                CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[Order ID] ) )
            VAR FirstStart =
                MINX ( CurrentIDTable, 'Table'[From] )
            VAR LastEnd =
                MAXX ( CurrentIDTable, 'Table'[To] )
            RETURN
                DATEDIFF ( FirstStart, LastEnd, MINUTE )
        )
  • hi Wirestat 

    try to plot a table visual  with the order id column and a measure like:

    Duration = 
    MAXX(
        TableName,
        TableName[To]            
    )
    -
    MINX(
        TableName,
        TableName[From]
    )

     

    it worked like:

     

    your from and to columns shall include date info, with date info, you shall get the correct duration for 1305300 as well.