The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event! Join us in Stockholm, Sweden from September 24-27, 2024.
2-for-1 sale on June 20 only!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
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.
Solved! Go to Solution.
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 :
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
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 :
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
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)
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 :
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
As you see in the data tab everything looks great but on the report tab this is what I get
In Power Query, create a custom column as follows:
#duration(0, 0, 0, [Total seconds])
If you prefer DAX, see the link below:
https://community.powerbi.com/t5/Community-Blog/Aggregating-Duration-Time/ba-p/22486
Proud to be a Super User!
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 ?
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]
Proud to be a Super User!
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the June 2024 Power BI update to learn about new features.
User | Count |
---|---|
99 | |
93 | |
82 | |
64 | |
58 |
User | Count |
---|---|
248 | |
123 | |
112 | |
79 | |
78 |