cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
c-iakovidou
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. 

c-iakovidou_0-1623150088493.png

 

1 ACCEPTED SOLUTION
Ailsa-msft
Community Support
Community Support

Hi @c-iakovidou 

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 :

Ailsamsft_0-1623919286283.png

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

View solution in original post

9 REPLIES 9
Ailsa-msft
Community Support
Community Support

Hi @c-iakovidou 

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 :

Ailsamsft_0-1623919286283.png

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

View solution in original post

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)

Ailsa-msft
Community Support
Community Support

Hi @c-iakovidou 

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 :

Ailsa-msft_0-1623308993911.png

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.

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

Hi @c-iakovidou 

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 ?

Hi again Ailsa, 

 

I've did what you mentioned above and came to this 

duration.PNG

  

duration report.PNG

As you see in the data tab everything looks great but on the report tab this is what I get

DataInsights
Super User
Super User

@c-iakovidou,

 

In Power Query, create a custom column as follows:

 

#duration(0, 0, 0, [Total seconds])

 

DataInsights_0-1623162066223.png

 

If you prefer DAX, see the link below:

 

https://community.powerbi.com/t5/Community-Blog/Aggregating-Duration-Time/ba-p/22486 

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 ?

@c-iakovidou,

 

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]

 

Helpful resources

Announcements
PBI_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!