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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Calculated Table for Work Hours

Hi everyone,

I am new to DAX and have been playing around with this problem for a few days now. I have two tables with the same dimensionality of ~4000 rows (employees) by ~200 columns (dates). One records the time-ins of employees and the other records the time-outs in Date/Time format. My objective is to create a new calculated table with exactly the same dimensions (employees x dates) with the number of work hours the employees worked each day. I realize that calculating the work hours would involve using the DATEDIFF function but I would have to do it for all the column pairs (e.g. DATEDIFF(time_out[2015-01-01], time_in[2015-01-01], HOUR), DATEDIFF(time_out[2015-01-02], time_in[2015-01-02], HOUR), ...) --200 times!

 

How do I create an expression for the calculated table to apply the same DATEDIFF function on the corresponding cells of time-in and time-out tables and put the result in the work-hours table?

 

-Thanks!!

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

The straight answer is "you don't".

I think you could "unpivot other columns"  (in Power Query) from the employee id in each table and get yourself some columnar data like

emp_id date time_in

 

You could probably 'Merge as New' and join both tables on date and employee id.

That'll give you a table with emp_id date time_in time_out and you can use your DATEDIFF function to add another column.

View solution in original post

2 REPLIES 2
HotChilli
Super User
Super User

The straight answer is "you don't".

I think you could "unpivot other columns"  (in Power Query) from the employee id in each table and get yourself some columnar data like

emp_id date time_in

 

You could probably 'Merge as New' and join both tables on date and employee id.

That'll give you a table with emp_id date time_in time_out and you can use your DATEDIFF function to add another column.

Anonymous
Not applicable

Thanks so much HotChilli! That makes a lot of sense!!

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.