cancel
Showing results for
Did you mean: Regular Visitor

## Whole number to seconds and then time duration (dd:hh:mm:ss)

Hello guys!

I have a column which is called Total seconds. This is a Whole number column and the goal is to create a chart which shows the average duration time needed to complete a course. (the form I would like to present is this dd:hh:mm:ss

The only information I have are seconds. 1 ACCEPTED SOLUTION  Community Support

When you choose first, it will return the value of the first line of visual .

As for the average value you want, I have a method, maybe you can refer to it .Create calculated columns like these :

``````average seconds = AVERAGE('Table'[total seconds])

Duration average  =
VAR Duration = 'Table'[average seconds]
VAR Hours =INT ( Duration / 3600)
VAR Minutes =INT ( MOD( Duration - ( Hours * 3600 ),3600 ) / 60)
VAR Seconds =ROUNDUP(MOD ( MOD( Duration - ( Hours * 3600 ),3600 ), 60 ),0)
VAR H =IF ( LEN ( Hours ) = 1,
CONCATENATE ( "0", Hours ),
CONCATENATE ( "", Hours ))
VAR M =IF (
LEN ( Minutes ) = 1,
CONCATENATE ( "0", Minutes ),
CONCATENATE ( "", Minutes ))
VAR S =IF (
LEN ( Seconds ) = 1,
CONCATENATE ( "0", Seconds ),
CONCATENATE ( "", Seconds ))
RETURN
CONCATENATE (H,CONCATENATE ( ":", CONCATENATE ( M, CONCATENATE ( ":", S ) ) ) )
``````

And the result is as shown : You cannot directly add the original duration column directly to the card, because it cannot directly calculate the average value. You can calculate the average value of 'Table'[total seconds] first, then convert the average value, and add the converted value to the card .

I have attached my pbix file ,you can refer to it .

Best Regards

Community Support Team _ Ailsa Tao

9 REPLIES 9  Community Support

When you choose first, it will return the value of the first line of visual .

As for the average value you want, I have a method, maybe you can refer to it .Create calculated columns like these :

``````average seconds = AVERAGE('Table'[total seconds])

Duration average  =
VAR Duration = 'Table'[average seconds]
VAR Hours =INT ( Duration / 3600)
VAR Minutes =INT ( MOD( Duration - ( Hours * 3600 ),3600 ) / 60)
VAR Seconds =ROUNDUP(MOD ( MOD( Duration - ( Hours * 3600 ),3600 ), 60 ),0)
VAR H =IF ( LEN ( Hours ) = 1,
CONCATENATE ( "0", Hours ),
CONCATENATE ( "", Hours ))
VAR M =IF (
LEN ( Minutes ) = 1,
CONCATENATE ( "0", Minutes ),
CONCATENATE ( "", Minutes ))
VAR S =IF (
LEN ( Seconds ) = 1,
CONCATENATE ( "0", Seconds ),
CONCATENATE ( "", Seconds ))
RETURN
CONCATENATE (H,CONCATENATE ( ":", CONCATENATE ( M, CONCATENATE ( ":", S ) ) ) )
``````

And the result is as shown : You cannot directly add the original duration column directly to the card, because it cannot directly calculate the average value. You can calculate the average value of 'Table'[total seconds] first, then convert the average value, and add the converted value to the card .

I have attached my pbix file ,you can refer to it .

Best Regards

Community Support Team _ Ailsa Tao Regular Visitor

Thank you so much for your answer but unfortunately it does not solve my problem. I need the final view of the card to be interactive with the filters I have (eg. year, quarter etc)  Community Support

I used the data you provided to create a measure that can convert an integer into a duration .

``````Duration =
VAR Duration = SELECTEDVALUE('Table'[total seconds])
VAR Hours =
INT ( Duration / 3600)
VAR Minutes =
INT ( MOD( Duration - ( Hours * 3600 ),3600 ) / 60)
VAR Seconds =
ROUNDUP(MOD ( MOD( Duration - ( Hours * 3600 ),3600 ), 60 ),0)
VAR H =
IF ( LEN ( Hours ) = 1,
CONCATENATE ( "0", Hours ),
CONCATENATE ( "", Hours )
)
VAR M =
IF (
LEN ( Minutes ) = 1,
CONCATENATE ( "0", Minutes ),
CONCATENATE ( "", Minutes )
)
VAR S =
IF (
LEN ( Seconds ) = 1,
CONCATENATE ( "0", Seconds ),
CONCATENATE ( "", Seconds )
)
RETURN
CONCATENATE (
H,CONCATENATE ( ":", CONCATENATE ( M, CONCATENATE ( ":", S ) ) )
)``````

The effect is as shown : But regarding the average duration you said, I have a little problem. Because the data unit you provide is at the second level. If the final average has a decimal point, what should be done ? There is currently no way to directly convert a value with a decimal point into a duration.

I have attached my pbix file , you can refer to it .

Best Regards

Community Support Team _ Ailsa Tao

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

The format shown above is absolutely perfect but, I still have the problem with the avg duration. I need to have on the report tab a card that shows the Avg duration in this format: dd:hh:mm:ss  Community Support

How to deal with the number after the decimal point ? Is rounding directly reflected in the form of integers ?

For example :

The final average is 100.12, the returned result is 100, and the display in duration format is 00:01:40 .

Is this the result you want ? Regular Visitor

Hi again Ailsa,

I've did what you mentioned above and came to this  As you see in the data tab everything looks great but on the report tab this is what I get  Super User

In Power Query, create a custom column as follows:

``#duration(0, 0, 0, [Total seconds])`` If you prefer DAX, see the link below: Regular Visitor

Thank you so much for your answer! I have already tried this but unfortunately I could not display the average duration to have it as a card on the report tab.

Do you have any ideas ?  Super User

I would try the DAX solution (link in my previous message). In this solution, the measure [Duration in Seconds] would be your measure that calculates the average duration.

``VAR Duration = [Duration in Seconds]``  