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
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
Super User
Super User

@spandy34 Is this being done in Power Query?

 


@ 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...

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]
  )

@ 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...

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
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.