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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
mobul
Frequent Visitor

Aggregating and Visualising Duration Data

I have some data showing the number of hours worked but I'm not clear what modelling or formatting I need to do to be able to aggregate it and visualise it in PowerBI.

In power query editor I have 6 columns with the startTime & endTime as type Time and hours as type duration. The duration was not calculated, it was ingested.

 

Restriction

I have to use a particular version of PBI desktop that doesn't have dynamic formatting 

 

EmployeeIDDeptDatestartTimeendTimehoursWorked
abcddept101/01/202009:00:0020:00:000.11:00:00
abcddept102/01/202009:00:0020:15:000.11:15:00
jkldept101/01/202017:45:0018:15:000.00:30:00
jkldept201/03/202015:00:0015:30:000.00:30:00

 

I'd like to be able to visualise as charts

  • total hoursWorked per employeeID per month
  • total hoursWorked per dept per month

My issues are the

  1. hoursWorked column doesn't support sum (just count or count distinct) in the designer. In Power Query its type is duration, in report designer its data type is Time and there is no duration option.
  2. If i duplicate the hours and change it to type decimal then I can sum but can't figure out how to
    1. ensure the result is accurate
    2. format the result so its user friendly in days, hours mins. 
  3. Not clear what limitations apply or features exist that could help me

What I have tried.

Duplicating the hoursWorked value as a decimal

Creating a Measure SumFormatted = format(SUM('2019 to 2023'[hoursWorked]),"dd \d hh\h:mm:ss") which is returned as text but is returning a different result to the decimal sum assuming the int value represents days (24hours)

 

Any advice welcome on the power query, measures needed and limitations

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @mobul ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create calculated columns.

 

hoursWorked (h) = 
 var _start=CONVERT([Date]&" "&[startTime],DATETIME)
 var _end=CONVERT([Date]&" "&[endTime],DATETIME)
 RETURN DATEDIFF(_start,_end,SECOND)/3600
Month = MONTH([Date])
Year = YEAR([Date])

 

(3) We can create measures.

 

total hoursWorked per dept per month =
CALCULATE (
    SUM ( 'Table'[hoursWorked (h)] ),
    FILTER (
        ALLSELECTED ( 'Table' ),
        [Dept] = MAX ( 'Table'[Dept] )
            && [Year]
                IN VALUES ( 'Table'[Year] )
                    && [Month] IN VALUES ( 'Table'[Month] )
    )
)

total hoursWorked per employeeID per month =
CALCULATE (
    SUM ( 'Table'[hoursWorked (h)] ),
    FILTER (
        ALLSELECTED ( 'Table' ),
        [EmployeeID] = MAX ( 'Table'[EmployeeID] )
            && [Year]
                IN VALUES ( 'Table'[Year] )
                    && [Month] IN VALUES ( 'Table'[Month] )
    )
)

 

(4) Then the result is as follows.

vtangjiemsft_0-1718939522784.png

 

Best Regards,

Neeko Tang

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

Anonymous
Not applicable

Hi @mobul ,

 

You can create measures.

Format 1 = 
var _a=[total hoursWorked per dept per month]
var _b=ROUNDDOWN(_a,0)
var _c=_a-_b
return  SWITCH(TRUE(),
_b=0,_c*60 & "m",
_c=0, _b& "h",
_b&"h"&(_a-_b)*60&"m")
Format 2 = 
var _a=[total hoursWorked per employeeID per month]
var _b=ROUNDDOWN(_a,0)
var _c=_a-_b
return  SWITCH(TRUE(),
_b=0,_c*60 & "m",
_c=0, _b& "h",
_b&"h"&(_a-_b)*60&"m")

vtangjiemsft_0-1719198257835.pngvtangjiemsft_1-1719198278609.png

Best Regards,

Neeko Tang

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

3 REPLIES 3
Anonymous
Not applicable

Hi @mobul ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create calculated columns.

 

hoursWorked (h) = 
 var _start=CONVERT([Date]&" "&[startTime],DATETIME)
 var _end=CONVERT([Date]&" "&[endTime],DATETIME)
 RETURN DATEDIFF(_start,_end,SECOND)/3600
Month = MONTH([Date])
Year = YEAR([Date])

 

(3) We can create measures.

 

total hoursWorked per dept per month =
CALCULATE (
    SUM ( 'Table'[hoursWorked (h)] ),
    FILTER (
        ALLSELECTED ( 'Table' ),
        [Dept] = MAX ( 'Table'[Dept] )
            && [Year]
                IN VALUES ( 'Table'[Year] )
                    && [Month] IN VALUES ( 'Table'[Month] )
    )
)

total hoursWorked per employeeID per month =
CALCULATE (
    SUM ( 'Table'[hoursWorked (h)] ),
    FILTER (
        ALLSELECTED ( 'Table' ),
        [EmployeeID] = MAX ( 'Table'[EmployeeID] )
            && [Year]
                IN VALUES ( 'Table'[Year] )
                    && [Month] IN VALUES ( 'Table'[Month] )
    )
)

 

(4) Then the result is as follows.

vtangjiemsft_0-1718939522784.png

 

Best Regards,

Neeko Tang

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

Hi @Anonymous thanks for the help and thanks for the very clear response.

 

What is the benefit of creating measures when you sum the decimal value of the duration in seconds which you created as a calculated field instead of duplicating the worksWorked and transforming it into TotalSeconds

 

Also is there any way to show the values in hours and mins e.g. 11.00 is 11hr 00mins, 11.50 is 11hrs 30mins? My reason is its easier for readers but also when there is more data and hoursWorked then goes over 24hrs i think it makes more sense to talk about days worked instead of hours days

Anonymous
Not applicable

Hi @mobul ,

 

You can create measures.

Format 1 = 
var _a=[total hoursWorked per dept per month]
var _b=ROUNDDOWN(_a,0)
var _c=_a-_b
return  SWITCH(TRUE(),
_b=0,_c*60 & "m",
_c=0, _b& "h",
_b&"h"&(_a-_b)*60&"m")
Format 2 = 
var _a=[total hoursWorked per employeeID per month]
var _b=ROUNDDOWN(_a,0)
var _c=_a-_b
return  SWITCH(TRUE(),
_b=0,_c*60 & "m",
_c=0, _b& "h",
_b&"h"&(_a-_b)*60&"m")

vtangjiemsft_0-1719198257835.pngvtangjiemsft_1-1719198278609.png

Best Regards,

Neeko Tang

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

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.