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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
MNASRMOH
New Member

calculate how many hours between dates for each day separated

Hello,

 

I need help with creating the Dax formula to calculate how many hours between two dates for each day separately.

 

for example 

 

the below screenshot showing the employee has shift from 5 PM on the 10th of July to 2 AM the next day [9 hours], and take into consideration there is a relationship between this tale and calendar table and date is key column.

 

MNASRMOH_1-1630462604584.png

 

and the below screenshot showing the result when I use the matrix to visualize the data, showing 9 hours scheduled on the 10th of July which is wrong, it's supposed to be 7 hours only and 2 hours remaining must be moved to the day.

 

MNASRMOH_3-1630463169694.png

 

Thanks,

Nasr.

 

 

 

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

Hi, @MNASRMOH 

 

Try to create a calculated column like this:

Scheduled = 
DATEDIFF('Data'[Starts],'Data'[Date]+1+TIME(0,0,0),HOUR)

data:

vangzhengmsft_1-1630648155795.png

result:

vangzhengmsft_0-1630648083080.png

Please refer to the attachment below for details. Hope this helps.

 

Best Regards,
Community Support Team _ Zeon Zheng


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-angzheng-msft
Community Support
Community Support

Hi, @MNASRMOH 

 

Try to create a calculated column like this:

Scheduled = 
DATEDIFF('Data'[Starts],'Data'[Date]+1+TIME(0,0,0),HOUR)

data:

vangzhengmsft_1-1630648155795.png

result:

vangzhengmsft_0-1630648083080.png

Please refer to the attachment below for details. Hope this helps.

 

Best Regards,
Community Support Team _ Zeon Zheng


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

 

amitchandak
Super User
Super User

@MNASRMOH , are you looking to calculate business hours ?

refer if this can help

https://exceleratorbi.com.au/calculating-business-hours-using-dax/

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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