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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
sushmitasur4
Regular Visitor

Calculating Time Difference between Start and End Timestamps excluding overlapping of multiple rows.

We need a calculated Column/Measure that can calculate the time difference excluding the overlapping time between two Timestamp Columns: Start Time and End Time.

Each Row represents an event in the table. The Output (Minutes) column [Time Format – Minutes] is our desired output and the total is the calculated sum of the Output we need in Minutes format.

 

Basically, when there is any overlapping of time, we consider the start time stamp of first overlapped event and the end timestamp of last overlapped event.

 

Demo.png

 

For Example: Event 7 starts at 13:40PM on 28th and ends at 16:00PM of the same date. The Output can be 140 Minutes Time difference, but we have Event 8 that starts at 15:00PM which has overlapped between with the timing /Duration of Event 7. It ends at 17:50PM. Hence, we will take start time of Event 7 and End time of Event 8 and calculate the time difference that is 250 Minutes. This calculation goes on throughout the table.

 

Kindly help with the Calculation

Warm Regards.

1 ACCEPTED SOLUTION
v-jianpeng-msft
Community Support
Community Support

Hi,  @sushmitasur4 

First of all,
Here is a reference, I did some processing to your data, you can use [Date]+[Time] to get the [Date/Time] Column:

vjianpengmsft_0-1709805925146.png
Add an index column for identification:

Sort =
SWITCH (
    TRUE (),
    'Table'[Event Num] IN { 1, 2 }, "1",
    'Table'[Event Num] = 3, "2",
    'Table'[Event Num] IN { 4, 5, 6 }, "3",
    'Table'[Event Num] IN { 7, 8 }, "4"
)

vjianpengmsft_4-1709806159739.png


Then create a calculate table:

Table 2 =
FILTER (
    CROSSJOIN (
        SELECTCOLUMNS ( 'Table', "Sort1", 'Table'[Sort], "Start1", 'Table'[Start] ),
        SELECTCOLUMNS ( 'Table', "Sort2", 'Table'[ Sort], "End2", 'Table'[End] )
    ),
    [Sort1] = [Sort2]
)

vjianpengmsft_5-1709806199993.png

At last, add a table visual, The result is as follow:

 vjianpengmsft_2-1709805997235.jpeg

 

 

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

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

 

 

 

 

 

View solution in original post

1 REPLY 1
v-jianpeng-msft
Community Support
Community Support

Hi,  @sushmitasur4 

First of all,
Here is a reference, I did some processing to your data, you can use [Date]+[Time] to get the [Date/Time] Column:

vjianpengmsft_0-1709805925146.png
Add an index column for identification:

Sort =
SWITCH (
    TRUE (),
    'Table'[Event Num] IN { 1, 2 }, "1",
    'Table'[Event Num] = 3, "2",
    'Table'[Event Num] IN { 4, 5, 6 }, "3",
    'Table'[Event Num] IN { 7, 8 }, "4"
)

vjianpengmsft_4-1709806159739.png


Then create a calculate table:

Table 2 =
FILTER (
    CROSSJOIN (
        SELECTCOLUMNS ( 'Table', "Sort1", 'Table'[Sort], "Start1", 'Table'[Start] ),
        SELECTCOLUMNS ( 'Table', "Sort2", 'Table'[ Sort], "End2", 'Table'[End] )
    ),
    [Sort1] = [Sort2]
)

vjianpengmsft_5-1709806199993.png

At last, add a table visual, The result is as follow:

 vjianpengmsft_2-1709805997235.jpeg

 

 

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

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

 

 

 

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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