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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
spandy34
Responsive Resident
Responsive Resident

Calculating time Midnight

I have the table below.  I have a Plannned Entry Time and a Planned Exist Time and a Planned Duration which are all Time fields.  I have used the following formula for the Planned Duration Column

Planned Duration = [PlannedExitTime]-[PlannedEntryTime].  It works okay until like the example the Planned Entry TIme is 23:45:00 and then the Planned Exit Time is Midnight.  The Planned Duration states 23:45:00 instead of 00:15:00
 
Can someone help with the formula in the Planned Duration Column to resolve this please.

@amitchandak @Greg_Deckler 

 

spandy34_0-1678813451109.png

 

1 ACCEPTED SOLUTION

THis has solved it - thank you so much for your help

Planned Duration =
  IF(
    [PlannedExitTime] = TIME(0,0,0),
   (TIME(23,59,59)- 'Procurement_Main_Data'[PlannedEntryTime])+TIME(0,0,1),
   [PlannedExitTime] - [PlannedEntryTime]
  )

View solution in original post

7 REPLIES 7
Greg_Deckler
Community Champion
Community Champion

@spandy34 Is this being done in Power Query?

 



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

No not power query . I just added the column in the table imported from an sql database 

@spandy34 OK, try this:

Planned Duration = 
  IF(
    [PlannedExitTime] = TIME(0,0,0),
    (TIME(23:59:59) - [PlannedEntryTime) + TIME(0,0,1),
    [PlannedExitTime] - [PlannedEntryTime]
  )


Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

THis has solved it - thank you so much for your help

Planned Duration =
  IF(
    [PlannedExitTime] = TIME(0,0,0),
   (TIME(23,59,59)- 'Procurement_Main_Data'[PlannedEntryTime])+TIME(0,0,1),
   [PlannedExitTime] - [PlannedEntryTime]
  )

Hi @Greg_Deckler 

 

Ive tried adding a column with the above Dax and I am getting the error below

spandy34_0-1678820167105.png

 

AndrewPF
Helper V
Helper V

Are you taking into account the fact that anything after midnight is the following day? 

Do your time fields include a date? 

See also: 

Solved: Concatenate date and time from different columns i... - Microsoft Power BI Community

spandy34
Responsive Resident
Responsive Resident

no it doesn't include a date. I think that was the problem . I think I need some DAX thst says if the time equals midnight then it's handled differently than just [PlannedExitTime]-[PlannedEntryTime]

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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