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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Ashfaq
Regular Visitor

Calculate Hours Late for Employee

Hello Experts,

 

I do have below data sets in my Source Database table.

The standard in and out times of employees are from 08:00 A.M till 02:00 P.M.

 

EmpDateRef_IN_TimeIN_TimeRef_OUT_TimeOUT_Time
1015-Dec-188:008:5014:0012:10
1025-Dec-188:009:0014:0013:30
1035-Dec-188:0010:4514:0011:30
1045-Dec-188:008:0014:0014:00
1055-Dec-188:008:0014:0014:00


for Example emp 101 is late for 50 Minutes in morning and he left early and he is late for 1 hour 50 Minutes in evening.

So in total ths employee is late for 2:40 2 hour and 40 Minutes for today.
In power BI I need to Calculate No of hours each employee he is absent in HH:MM

 

EmpDateRef_IN_TimeIN_TimeRef_OUT_TimeOUT_TimeLateStatus
1015-Dec-188:008:5014:0012:102:40Late
1025-Dec-188:009:0014:0013:301:30Late
1035-Dec-188:0010:4514:0011:302:45Late
1045-Dec-188:008:0014:0014:000:00Ontime
1055-Dec-188:008:0014:0014:000:00

Ontime

 

 

Now I need to Populate last 2 coulumns in power BI, Can somebody please provide there inputs on how to solve this.

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

I would do this in 3 columns:

 

Column = DATEDIFF([Ref_IN_Time],[IN_Time],MINUTE)+DATEDIFF([OUT_Time],[Ref_OUT_Time],MINUTE)


Status = IF([Column]=0,"On Time","Late")


Late = 
VAR __hours = INT([Column]/60)
VAR __minutes = [Column] - 60*__hours
RETURN CONCATENATE(CONCATENATE(__hours,":"),__minutes)

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

I would do this in 3 columns:

 

Column = DATEDIFF([Ref_IN_Time],[IN_Time],MINUTE)+DATEDIFF([OUT_Time],[Ref_OUT_Time],MINUTE)


Status = IF([Column]=0,"On Time","Late")


Late = 
VAR __hours = INT([Column]/60)
VAR __minutes = [Column] - 60*__hours
RETURN CONCATENATE(CONCATENATE(__hours,":"),__minutes)

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thank you @Greg_Deckler, It worked like a charm,

 

I do have one more question, But i will open another post for that.

 

Regards

ASHFAQ

AlB
Super User
Super User

Hi @Ashfaq

Employee 103 shouldn't be 2:45+ 2:30= 5:15 hours late?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.