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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
bibhash_21
Frequent Visitor

How to calculate hours per date from start datetime and end datetime

Hi,

 

Some shifts will cross midnight.  These will have to be seperated by calendard day
For example: clock in at 9PM on 11/19/19 and clock out at 9AM on 11-20-19.  this should show 3 hours on 11-19-19 and 9 hours on 11-20-19.  this reproting will have to combine hours from all events that occur in that calendar day

My Table

table1

Event NameStart DateTimeEnd DateTime
Event111/22/2019 21:0011/23/2019 9:00
Event211/22/2019 16:0011/23/2019 15:00
Event311/24/2019 17:0011/26/2019 3:00
Event411/25/2019 10:0011/25/2019 18:00
Event511/25/2019 19:0011/25/2019 23:00

 

and want like this

 

Event NameDatetime(hours)
Event111/22/193
Event111/23/199
Event211/22/198
Event211/23/1915
Event311/24/197
Event311/25/1924
Event311/26/193
Event411/25/198
Event511/25/194

 

pls give me dax solution

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

Hi @bibhash_21 ,

My original data table (Append3):

d17.PNG

In 'Edit Query':

First, get this table:

d19.PNG

My method:

copy the original table,

then ,swap the names and positions of the two columns (Start date & End date),

d21.PNGd22.PNG

then ,use 'Append' feature,

then, change 'Data type' of 'Date1' (I also change the name of the column )

then, choose 'Event Name' column and 'Data1' column, click ' Remove duplicate rows',

then, you can get ‘Append3’.

 

Second, get this table:

d24.PNG

My method: https://www.poweredsolutions.co/2019/07/23/fill-dates-between-dates-with-power-bi-power-query/ 

If you want to complete the step, you'd better get another data table which don't have time, like this table:

d18.PNG

 

In 'Data View':

First, create a column in 'Append3':

 

Time = 
24- HOUR(Append3[Date2])

 

Then, create a column in 'Sheet5':

 

Column = 
LOOKUPVALUE(
    Append3[Time],
    Append3[Date1], Sheet5[Custom],
    Append3[Event Name], Sheet5[Event Name]
)
Time = 
IF(
    Sheet5[Column] <> BLANK(),
    Sheet5[Column],
    24
)

 

d26.PNG

 

Best regards,
Lionel Chen

 

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

2 REPLIES 2
v-lionel-msft
Community Support
Community Support

Hi @bibhash_21 ,

My original data table (Append3):

d17.PNG

In 'Edit Query':

First, get this table:

d19.PNG

My method:

copy the original table,

then ,swap the names and positions of the two columns (Start date & End date),

d21.PNGd22.PNG

then ,use 'Append' feature,

then, change 'Data type' of 'Date1' (I also change the name of the column )

then, choose 'Event Name' column and 'Data1' column, click ' Remove duplicate rows',

then, you can get ‘Append3’.

 

Second, get this table:

d24.PNG

My method: https://www.poweredsolutions.co/2019/07/23/fill-dates-between-dates-with-power-bi-power-query/ 

If you want to complete the step, you'd better get another data table which don't have time, like this table:

d18.PNG

 

In 'Data View':

First, create a column in 'Append3':

 

Time = 
24- HOUR(Append3[Date2])

 

Then, create a column in 'Sheet5':

 

Column = 
LOOKUPVALUE(
    Append3[Time],
    Append3[Date1], Sheet5[Custom],
    Append3[Event Name], Sheet5[Event Name]
)
Time = 
IF(
    Sheet5[Column] <> BLANK(),
    Sheet5[Column],
    24
)

 

d26.PNG

 

Best regards,
Lionel Chen

 

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

Thank you so much @v-lionel-msft  for reply

but the time calculation is wrong.

Time should be

Event NameDatetime(hours)
Event111/22/193
Event111/23/199
Event211/22/198
Event211/23/1915
Event311/24/197
Event311/25/1924
Event311/26/193
Event411/25/198
Event511/25/194

 

Pls reply

 

 

 

 

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors