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

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

Reply
kbachova
Advocate II
Advocate II

How do I refer to overtime handling?

Hi all,

 

I am quite new (and still learning) to power BI and DAX and have been trying to figure out a way how to refer to time (hours, minutes) of the day that is considered as overtime. I have lifts hapening in regular time and lifts happening in overtime. Overtime is assumed to be 00:00 - 7:59 and 20:00 - 23:59.

For my instance I need to filter for overtime hours to see from my data hom many tonnes have been lifted in the overtime.

 

What I have tried was to use:

 

Tonnage lifted in overtime indicator = CALCULATE(SUM(CargoLineDetail[BaseEntity_id]), CargoLineDetail[LiftTime]<= TIME(07,59,0) && CargoLineDetail[LiftTime]>=TIME(20,0,0))

 

Which does not seem to work, especially referencing to time.

 

I also tried to do:

 

Overtime indicator COLUMN = If(CargoLineDetail[LiftTime]<= TIME(07,59,0) && CargoLineDetail[LiftTime]>=TIME(20,0,0),1,0)

 

Which again, does not seem to work properly - referencing to time.

 

Can anyone advise what the correct logic should be here?

 

Thank you!

 

Kristina

 

1 ACCEPTED SOLUTION

Hi Simon_Hou,

 

thank you for your advice. I tried that, but didn't work (the data type of my column was date time) and in the meantime I just created a different workaround and only decided to take the hours as a reference. So what I did is that I created a separate column (in query editor I created a column for time only and from that column i derived the hours column) for hours and just used the following formula and it will do for now:

 

OvertimeLIFTSindicatorCOLUMN = If(OR(CargoLineDetail[HOURS]>=20,CargoLineDetail[HOURS]<=7),1,0)

 

Kristina

 

 

View solution in original post

3 REPLIES 3
v-sihou-msft
Microsoft Employee
Microsoft Employee

@kbachova

 

What's the data type of "CargoLineDetail[LiftTime]"? In Power BI Desktop, it only has "Date Time" type. I assume your CargoLineDetail[LiftTime] field is "Date Time" type. To compare Time, you can use HOUR(), MINUTE() and SECOND() function to retrieve the different part and generate a TIME() for comparison. It should work properly.

 

Overtime indicator COLUMN = 
If(
TIME(HOUR(CargoLineDetail[LiftTime]),MINUTE(CargoLineDetail[LiftTime]),SECOND(CargoLineDetail[LiftTime]))
<= TIME(07,59,0) 
&&
TIME(HOUR(CargoLineDetail[LiftTime]),MINUTE(CargoLineDetail[LiftTime]),SECOND(CargoLineDetail[LiftTime]))
>=TIME(20,0,0),
1,0)

 

 

Regards,

 

Hi Simon_Hou,

 

thank you for your advice. I tried that, but didn't work (the data type of my column was date time) and in the meantime I just created a different workaround and only decided to take the hours as a reference. So what I did is that I created a separate column (in query editor I created a column for time only and from that column i derived the hours column) for hours and just used the following formula and it will do for now:

 

OvertimeLIFTSindicatorCOLUMN = If(OR(CargoLineDetail[HOURS]>=20,CargoLineDetail[HOURS]<=7),1,0)

 

Kristina

 

 

MattAllington
Community Champion
Community Champion

You really need to provide more Information here. The correct formula will depend on your data model, which includes information about the tables, the columns, and the relationships.

 

can you post a link to a sample workbook?



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

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!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.

Top Solution Authors
Top Kudoed Authors