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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
zinminthant
Regular Visitor

Time duration between multiple events with start and stop

Hello,

 

I would like to calculate duration of Start/Stop of multime events at the time of event Stop. Below is the example. How can I write measure/column in DAX to calculate the duration? 

Date TimeEventsDuration (hr)

1/11/2020 1:00Start A 
1/11/2020 2:00Stop A1
1/11/2020 3:00Start A 
1/11/2020 3:00Others 
1/11/2020 4:15Start B 
1/11/2020 5:00Stop B0.75
1/11/2020 6:00Stop A3
1/11/2020 7:00Start C 
1/11/2020 8:00Start A 
1/11/2020 9:00Stop C2
1/11/2020 10:00Start B 
1/11/2020 11:00Stop A3
1/11/2020 11:30Stop B1.5

 

Best Regards,

Zin. 

2 ACCEPTED SOLUTIONS
AlB
Super User
Super User

Hi @zinminthant 

You'd have to split the Events column to have the type of the event (Start, Stop...)  and the name of the entity the event happens on (A, B...) in separate columns. Best to do this in Power query. Then you can create a column like this:

Duration (hr) =
VAR previousStart_ =
    CALCULATE (
        MAX ( Table1[DateTime] ),
        ALLEXCEPT ( Table1, Table1[Entity] ),
        Table1[Event Type] = "Start",
        Table1[DateTime] < EARLIER ( Table1[DateTime] )
    )
RETURN
    IF ( Table1[Event Type] = "Stop", ( Table1[DateTime] - previousStart_ ) * 24 )

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

View solution in original post

AlB
Super User
Super User

@zinminthant 

See it all at work in the attached file.

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

View solution in original post

2 REPLIES 2
AlB
Super User
Super User

@zinminthant 

See it all at work in the attached file.

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

AlB
Super User
Super User

Hi @zinminthant 

You'd have to split the Events column to have the type of the event (Start, Stop...)  and the name of the entity the event happens on (A, B...) in separate columns. Best to do this in Power query. Then you can create a column like this:

Duration (hr) =
VAR previousStart_ =
    CALCULATE (
        MAX ( Table1[DateTime] ),
        ALLEXCEPT ( Table1, Table1[Entity] ),
        Table1[Event Type] = "Start",
        Table1[DateTime] < EARLIER ( Table1[DateTime] )
    )
RETURN
    IF ( Table1[Event Type] = "Stop", ( Table1[DateTime] - previousStart_ ) * 24 )

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.