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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
mo1988
Helper I
Helper I

Date/Time Calculation Matrix Issue

Sample.png
Hi there,

 

I am trying to calculate the total shift duration worked by employees by using Datediff between Login & Logout. Since there could be more than just 1 login/logout in a day due to interruption, I am using the following measure:

 

Shift Duration = VAR MinimumShift = MIN(Data[Login])
VAR MaximumShift = MAX(Data[Logout])
VAR DifferenceSeconds = CALCULATE(DATEDIFF(MinimumShift, MaximumShift, SECOND))
VAR Hours = INT(DifferenceSeconds/3600)
VAR Minutes = INT(MOD(DifferenceSeconds-(Hours*3600),3600)/60)
VAR Seconds = ROUNDUP(MOD(MOD(DifferenceSeconds-(Hours*3600),3600),60),0)
RETURN
Hours*10000+Minutes*100+Seconds

 

 

The purpose for this measure is to calculate the difference between login & logout taking into consideration multiple rows for the same employee and same date, and also to return the result in HH;MM;SS after formatting it.

 

This is working just fine on row level of a table/matrix, but it is not calculating properly on column/row totals.

 

Can you please advise? Thank you 

1 ACCEPTED SOLUTION
AllisonKennedy
Super User
Super User

@mo1988  You need to provide the same context to the measure as you've provided with the table visual. 

https://dax.guide/functions/table-manipulation/ should help you do this.

 

Try something like: 

 

Shift Duration Final = 
SUMX ( SUMMARIZE ( Data, Data[EmployeeID], Data[DateKey] ) , [Shift Duration] ) 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

2 REPLIES 2
AllisonKennedy
Super User
Super User

@mo1988  You need to provide the same context to the measure as you've provided with the table visual. 

https://dax.guide/functions/table-manipulation/ should help you do this.

 

Try something like: 

 

Shift Duration Final = 
SUMX ( SUMMARIZE ( Data, Data[EmployeeID], Data[DateKey] ) , [Shift Duration] ) 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Thank you @AllisonKennedy - It worked like a charm 🙂 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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