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

Duration data as an average and hh:nn:ss

Good day all,

I have the following data input:

Skill, Date, Calls, Time

Ed, 1/2/21, 10,37.00

Ed, 1/3/21, 12, 36.00

Ted, 1/1/21, 12, 7.00

Ted, 1/2/21, 11, 6.00

Fred, 1/1/21, 27, 12.00

Fred, 1/2/21, 26, 11.00

 

There are multiple rows by date, this is just a sample.

Time is imported as text. Converted in Query Editor to duration and a new column created for Duration.TotalSeconds([Time])

In the PBI desktop, the time shows as Whole Nuber (0 places)

I create a Matrix and pull in my data as shown all is good and I get the ability to show the time as an average per skill and filter by date, cool. Trouble is the Time is in seconds and I want it in h:nn:ss or nn:ss (management are not going to want to calculate what 365 seconds is, they want to see 6:05.

Everything I try to do formatiting as a date, when I pull it into the Matrix, it won't average. Excel, where are you when I need you?

 

wac1ldy_0-1611172100486.png

I'm relatively new to PBI so any pointers you can give me would be appreciated.

Tx. CW

1 ACCEPTED SOLUTION
d_gosbell
Super User
Super User

You can't do an average of a Time column, but you can do an average of a seconds column and then convert that to a time and format it as hh:nn:ss - the only thing to be aware of is that your average times need to be under 24hrs otherwise this technique will not work as there is no way to display the days (so 2 days and 7hrs would just show as 7hrs)

 

A measure that does this would look something like the following:

 

Avg Duration =
var avgDuration = AVERAGE('Table'[Duration])
var hours = INT( avgDuration / (3600) )
var minutes = int( (avgDuration - hours * 3600) / (60) )
var seconds = mod(avgDuration,60)
return time(hours, minutes, seconds)

View solution in original post

3 REPLIES 3
wac1ldy
Frequent Visitor

Thanks guys. Great information and a great lesson for me. After reading your "pointers", what fixed it for me was building a measure with the average and the formatting in the right order. as always, I was overthinking it. CW

d_gosbell
Super User
Super User

You can't do an average of a Time column, but you can do an average of a seconds column and then convert that to a time and format it as hh:nn:ss - the only thing to be aware of is that your average times need to be under 24hrs otherwise this technique will not work as there is no way to display the days (so 2 days and 7hrs would just show as 7hrs)

 

A measure that does this would look something like the following:

 

Avg Duration =
var avgDuration = AVERAGE('Table'[Duration])
var hours = INT( avgDuration / (3600) )
var minutes = int( (avgDuration - hours * 3600) / (60) )
var seconds = mod(avgDuration,60)
return time(hours, minutes, seconds)
lbendlin
Super User
Super User

use #time - PowerQuery M | Microsoft Docs or #duration - PowerQuery M | Microsoft Docs to create a new column in Power Query

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.