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
metoo
Frequent Visitor

Trying to work out duration with date time columns and another with minutes

Hi there all, 

 

I'm trying to work out a total hours and minutes duration between a start time, end time and then add a to the duration. How can I do this in power bi desktop? (I only need the end calculation of the total time in hours and minutes). 

 

 DataTimeMinutes.jpg

 

Thanks 

 

2 ACCEPTED SOLUTIONS

Hi @metoo ,

You can create a calculated column as below to get it:

Column = 
VAR _Seconds =
    (
        DATEDIFF ( 'Table'[RosterStartTime], 'Table'[RosterEndTime], MINUTE ) + 'Table'[TravelTimeFinal]
    ) * 60
VAR _Minutes =
    INT ( DIVIDE ( _Seconds, 60 ) )
VAR _RemainingSeconds =
    MOD ( _Seconds, 60 )
VAR _Hours =
    INT ( DIVIDE ( _Minutes, 60 ) )
VAR _RemainingMinutes =
    MOD ( _Minutes, 60 )
RETURN
    FORMAT ( _Hours, "00" ) & ":"
        & FORMAT ( _RemainingMinutes, "00" ) & ":"
        & FORMAT ( _RemainingSeconds, "00" )

vyiruanmsft_0-1702375184508.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Hi @metoo ,

According to your screenshot, it seems that you are trying to create a custom column in Power Query Editor. Please create a calculated column by DAX instead of creating a custom column.

Solved: Power Query Custom Column vs. Calculated Column: P... - Microsoft Fabric Community

Power BI: Custom Column Vs Calculated Column | Power BI 

vyiruanmsft_0-1702442013876.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
SamInogic
Super User
Super User

Hi @metoo ,

In Power BI, we have DateDiff function to calculate the difference between dates in various intervals such as Hour, Minutes, etc. 

So, you can use below expression to calculate difference in Hours,

DATEDIFF(RoasterTable[Roaster Start Time],RoasterTable[Roaster End Time],HOUR)

If you want to calculate difference in Hours and minutes, then create a custom column with below expression,

Duration = DATEDIFF(RoasterTable[Roaster Start Time],RoasterTable[Roaster End Time],HOUR) & " Hour "  &MOD(DATEDIFF(RoasterTable[Roaster Start Time],RoasterTable[Roaster End Time],MINUTE),60) & " Minutes"

Please refer to the below screenshot ,

SamInogic_0-1701840142527.png

Thanks!

 

Inogic Professional Service Division

An expert technical extension for your techno-functional business needs

Power Platform/Dynamics 365 CRM

Drop an email at crm@inogic.com

Service:  http://www.inogic.com/services/ 

Power Platform/Dynamics 365 CRM Tips and Tricks:  http://www.inogic.com/blog/

Thanks SamInogic for that information. Sorry I wasnt clear in my questions. What I was really saying was I would like the final column to contain both the duration and the added travel time for the shift as well. The format would be hours and minutes.  So in the eg above, it would be 1.30 minutes duration + the travel time, so all up 1.45 minutes. 

 

Cheers

Metoo 

ps: if you need to know using power bi desktop. 

Hi @metoo ,

You can create a calculated column as below to get it:

Column = 
VAR _Seconds =
    (
        DATEDIFF ( 'Table'[RosterStartTime], 'Table'[RosterEndTime], MINUTE ) + 'Table'[TravelTimeFinal]
    ) * 60
VAR _Minutes =
    INT ( DIVIDE ( _Seconds, 60 ) )
VAR _RemainingSeconds =
    MOD ( _Seconds, 60 )
VAR _Hours =
    INT ( DIVIDE ( _Minutes, 60 ) )
VAR _RemainingMinutes =
    MOD ( _Minutes, 60 )
RETURN
    FORMAT ( _Hours, "00" ) & ":"
        & FORMAT ( _RemainingMinutes, "00" ) & ":"
        & FORMAT ( _RemainingSeconds, "00" )

vyiruanmsft_0-1702375184508.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thansk for the repsonse. I'm getting a eof error when trying to add. Do you think this could be related to the data types? I've tried duplicating the start and end columns and confirming date/time. That didnt help. The travel time column is formated as decimal number. There will be a lot of zeros in this data. Eof.jpg

Hi @metoo ,

According to your screenshot, it seems that you are trying to create a custom column in Power Query Editor. Please create a calculated column by DAX instead of creating a custom column.

Solved: Power Query Custom Column vs. Calculated Column: P... - Microsoft Fabric Community

Power BI: Custom Column Vs Calculated Column | Power BI 

vyiruanmsft_0-1702442013876.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you very much, calculated beautifully. 

 

Sorry one final question, how can this number be summed?  (using a slicer to work out the fortnight). Matching the total hour+ travel time against another column called minimum hours. 

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.