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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
RussHaight
New Member

Calculate Time

Hello,

I'm trying to figure out a way to calculate time diff. In the table the time in and time out are in the same field with a punch type determining if it was in or out

 

Table structure is like this.

 

punch date/time                        employee #    punch time     punch type

9/11/2023 8:00:00 am                 00000            8:00 am               ID

9/11/2023 4:00:00 pm                 00000            4:00 pm              OD

 

ID being in day and OD being out day

 

Thank you in advance

1 ACCEPTED SOLUTION

sorry-had an extra ], I removed it now I don't get the red )

Thank you-I'm going to see if I can leverage a measure as to what I am trying to do-which is calculate hours workd by employee_number on any given day/week/month/etc

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

I  am trying to caluculate the time for each course. I have a start time and end time for the trianing and waniting to add another column that shows the total hours of each course 

Enrolment NameEnrolment Start TimeEnrolment End Time
Complaints Handling 15/01/20248:00 AM5:00PM
Motor Lodgement 05 - 23/02/20248:30 AM4:30PM

 

Dangar332
Super User
Super User

hi, @RussHaight 

try below measure. It might help

timediff =
var g =MIN('time'[punch date/time])
var a = CALCULATE(MAX('time'[punch date/time]),'time'[punch type]="id")
var b = CALCULATE(MAX('time'[punch date/time]),'time'[punch type]="od")
var c =CALCULATE(DATEDIFF(a,b,HOUR),'time'[punch date/time]=g)
return
c
 
Dangar332_0-1698327304827.png
 
 
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

Hi, @RussHaight 

 

If above post helps, then please consider Accepting it as the solution to help the other members find it more quickly

Thank you for your reply. Copying and pasting what you wrote throws a lot of red so I changed it to what i think you are explaining to me but I get the following error. 

 

Also, is this formula supposed to be a measure or an added column on the punch table? 

 

RussHaight_0-1698330422370.png

 

hi, @RussHaight 

it's a measure.

and remove   ))  from code  it give you answer

 

timediff =
var g =MIN('time'[punch date/time])
var a = CALCULATE(MAX('time'[punch date/time]),'time'[punch type]="id")
var b = CALCULATE(MAX('time'[punch date/time]),'time'[punch type]="od")
var c =CALCULATE(DATEDIFF(a,b,HOUR),'time'[punch date/time]=g)
return
c
 
in above code red part is table name i use as 'time' so replace your table name with 'time'

the red ) is added automatically when I click out of the code window and if I hit enter again while in the code window, it adds another one, and so on.

 

so after Return

c

I click out and it adds one ), I click in and then out, it adds another one ))

sorry-had an extra ], I removed it now I don't get the red )

Thank you-I'm going to see if I can leverage a measure as to what I am trying to do-which is calculate hours workd by employee_number on any given day/week/month/etc

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.