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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Wirestat
Frequent Visitor

Find Order Duration based on Start Stop time

Hello, please can you help to find order duration based on starting and finishing time 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
3 REPLIES 3
tamerj1
Super User
Super User

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 )
)
v-yangliu-msft
Community Support
Community Support

Hi  @Wirestat ,

 

 

Here are the steps you can follow:

1. . In Power Query -- Create Indices for the two tables -- Add Column – Index Column – From 1.

vyangliumsft_0-1677033581035.png

2. Create calculated column.

Rank =
RANKX(
    FILTER(ALL('Table'),'Table'[Order id]=EARLIER('Table'[Order id])),[Index],,ASC)
Flag =
VAR _mindate =
    MINX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[Order id] = EARLIER ( 'Table'[Order id] )
                && 'Table'[Rank]
                    = MINX (
                        FILTER ( ALL ( 'Table' ), 'Table'[Order id] = EARLIER ( 'Table'[Order id] ) ),
                        [Rank]
                    )
        ),
        [From]
    )
VAR _maxdate =
    MAXX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[Order id] = EARLIER ( 'Table'[Order id] )
                && 'Table'[Rank]
                    = MAXX (
                        FILTER ( ALL ( 'Table' ), 'Table'[Order id] = EARLIER ( 'Table'[Order id] ) ),
                        [Rank]
                    )
        ),
        [To]
    )
VAR _datediff =
    DATEDIFF ( _mindate, _maxdate, MINUTE )
RETURN
    IF (
        'Table'[Order id] = 0,
        BLANK (),
        IF (
            VALUE ( LEFT ( _mindate, FIND ( ":", _mindate ) - 1 ) )
                < VALUE ( LEFT ( _maxdate, FIND ( ":", _maxdate ) - 1 ) ),
            _datediff + 24 * 60,
            _datediff
        )
    )
Time =
var _hour=
QUOTIENT('Table'[Flag],60)
var _minute=
MOD('Table'[Flag],60)
return
IF(
    [Flag]=BLANK(),BLANK(),
IF(
    'Table'[Rank]=
    MAXX(FILTER(ALL('Table'),'Table'[Order id]=EARLIER('Table'[Order id])),[Rank]),
TIME(
    _hour,_minute,0),BLANK()))

3. Result:

vyangliumsft_1-1677033581038.png

 

Best Regards,

Liu Yang

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

Hello @v-yangliu-msft 

Thank you but i get an error

Wirestat_0-1677059744007.png

 

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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