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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Need help getting an average of a calculated column

 

I am trying to get an average of the Duration column. Basic format is DD:HH:MM:SS.

duration.JPG

 

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

As tested, in my excel, the "duration" column is of time type or text type,

after importing to Power BI, i can go to Edit queries to transform it to duration type.

1.png

Then in Edit queries->Add columns->Duration->total seconds

2.png

Close&&apply, go to report view

Create measures

average = CALCULATE(AVERAGE(Sheet1[Total Seconds]),ALL(Sheet1))

total hours = INT(ROUNDDOWN([average]/3600,0))

Minutes = INT(ROUNDDOWN(([average]-[total hours]*3600)/60,0))

seconds = INT(ROUNDUP([average]-[total hours]*3600-[Minutes]*60,0))

days = INT(ROUNDDOWN([total hours]/24,0))

average format = [days]&"."&([total hours]-[days]*24)&":"&[Minutes]&":"&[seconds]

3.png

 

Best Regards

Maggie

 

Community Support Team _ Maggie Li
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
Amaury_VanEspen
Frequent Visitor

Hello

the duration data type does not accept to be summarized, any suggestion to get an average duration to use in a bar chart ?

Thank you

Amaury

v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

As tested, in my excel, the "duration" column is of time type or text type,

after importing to Power BI, i can go to Edit queries to transform it to duration type.

1.png

Then in Edit queries->Add columns->Duration->total seconds

2.png

Close&&apply, go to report view

Create measures

average = CALCULATE(AVERAGE(Sheet1[Total Seconds]),ALL(Sheet1))

total hours = INT(ROUNDDOWN([average]/3600,0))

Minutes = INT(ROUNDDOWN(([average]-[total hours]*3600)/60,0))

seconds = INT(ROUNDUP([average]-[total hours]*3600-[Minutes]*60,0))

days = INT(ROUNDDOWN([total hours]/24,0))

average format = [days]&"."&([total hours]-[days]*24)&":"&[Minutes]&":"&[seconds]

3.png

 

Best Regards

Maggie

 

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

Anonymous
Not applicable

Thank you very much, you have been a great help!!

Anonymous
Not applicable

What if you tried this measure:

Avg Duration = FORMAT(AVERAGE( Duration[Duration] ),"dd:hh:mm:ss")

Not sure how your data is set up, so that's more of a guess

Anonymous
Not applicable

Thanks, Nick. I've tried your suggestion and set up a new measure, but I still get the error : "MdxScript(Model) (4, 57) calculation error in measure 'Export Worksheet'[Avg Duration]: The function AVERAGE cannot work with values of type String.

Anonymous
Not applicable

You can try changing the data type in power query to type Duration. 

type duration.png

 

if the column errors out when you make that change (not sure where that column comes from) you will then have to calculate the duration yourself using whatever start and end points you want. 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.