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

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

Reply
dudeeee
Frequent Visitor

Unable to get correct sum for total working hours

Hello,
I am trying to calculate the total working hours from the given table between the date and time range. For each day I am getting the correct hours by subtracting two timestamps. But in the case of the total, the subtraction yields the hours between the two date ranges which is not what I need.
I want the sum of the total working hours which is the correct result. How can I achieve this and what am I doing wrong?
Here is the power bi visual table showing the data.

The measure formula I have used :

Total Working Hours = DATEDIFF([Lift First],[Lift Last],HOUR)

Here First Operation and Last Operation are both measures that gives min and max timestamp respectively.
YearMonthDayFirst OperationLast OperationTotal working hours
2022September59/5/2022 6:00:04 AM9/5/2022 1:06:02 PM7
2022September119/11/2022 5:07:46 AM9/11/2022 1:12:36 PM8
Total  9/5/2022 6:00:04 AM9/11/2022 1:12:36 PM151
1 ACCEPTED SOLUTION
v-yadongf-msft
Community Support
Community Support

Hi @dudeeee ,

 

This is my test table:

vyadongfmsft_0-1667551892219.png

 

Please try following DAX to create measures:

First Operation = MINX(FILTER(ALL('Table'),'Table'[Day] = SELECTEDVALUE('Table'[Day])),'Table'[Operation])

Last Operation = MAXX(FILTER('Table','Table'[Day] = SELECTEDVALUE('Table'[Day])),'Table'[Operation])

Hours = IF(ISINSCOPE('Table'[Year]),DATEDIFF([First Operation],[Last Operation],HOUR),SUMX('Table',DATEDIFF([First Operation],[Last Operation],HOUR)))

 

The result you want:

vyadongfmsft_1-1667552022949.png

 

Best regards,

Yadong Fang

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

3 REPLIES 3
v-yadongf-msft
Community Support
Community Support

Hi @dudeeee ,

 

This is my test table:

vyadongfmsft_0-1667551892219.png

 

Please try following DAX to create measures:

First Operation = MINX(FILTER(ALL('Table'),'Table'[Day] = SELECTEDVALUE('Table'[Day])),'Table'[Operation])

Last Operation = MAXX(FILTER('Table','Table'[Day] = SELECTEDVALUE('Table'[Day])),'Table'[Operation])

Hours = IF(ISINSCOPE('Table'[Year]),DATEDIFF([First Operation],[Last Operation],HOUR),SUMX('Table',DATEDIFF([First Operation],[Last Operation],HOUR)))

 

The result you want:

vyadongfmsft_1-1667552022949.png

 

Best regards,

Yadong Fang

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

RichardOfSydney
Regular Visitor

Sumx

can you elaborate in my problem's context?

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.