Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi,
I'm looking for a way to group time durations.
The raw data contains durations in format h:mm:ss:xxx :
| Duration action |
| 1:01:07.560 |
| 0:26:01.123 |
| 0:00:14.330 |
| 0:00:11.253 |
| 0:04:12.287 |
I want to add a grouped duration based on these groups:
| 0 - 30 sec |
| 30s - 1m |
| 1m - 2m |
| 2m - 5m |
| 5m - 15m |
| 15m - 30m |
| 30m - ∞ |
Desired result:
| Duration action | Grouped duration |
| 1:01:07.560 | 30m - ∞ |
| 0:26:01.123 | 15m - 30m |
| 0:00:14.330 | 0 - 30 sec |
| 0:00:11.253 | 0 - 30 sec |
| 0:04:12.287 | 2m - 5m |
Hope that there is someone that could help..
Many thanks in advance!!
Cheers,
Tim
Solved! Go to Solution.
Hello @TimR
you can ues nested if-statements like this
if [Duration action]<#duration(0,0,0,31) then "0 - 30 sec" else if [Duration action]<#duration(0,0,1,1) then "30s - 1m" else "etc."
here a complete example
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TYnJCcBADMR68TsMM/Yewa0Y999G9hFCQB9JVabkYWMuWl9lTF8nQR6vk6mBCP5c8Pn9kXL4va37AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Duration action" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Duration action", type duration}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Grouped duration", each if [Duration action]<#duration(0,0,0,31) then "0 - 30 sec" else if [Duration action]<#duration(0,0,1,1) then "30s - 1m" else "etc.")
in
#"Added Custom"
Copy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
Hello @TimR
use this code instead
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TYnJCcBADMR68TsMM/Yewa0Y999G9hFCQB9JVabkYWMuWl9lTF8nQR6vk6mBCP5c8Pn9kXL4va37AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Duration action" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Duration action", type duration}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Grouped duration", each try if [Duration action]<#duration(0,0,0,31) then "0 - 30 sec" else if [Duration action]<#duration(0,0,1,1) then "30s - 1m" else "etc." otherwise null)
in
#"Added Custom"
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
Hello @TimR
you can ues nested if-statements like this
if [Duration action]<#duration(0,0,0,31) then "0 - 30 sec" else if [Duration action]<#duration(0,0,1,1) then "30s - 1m" else "etc."
here a complete example
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TYnJCcBADMR68TsMM/Yewa0Y999G9hFCQB9JVabkYWMuWl9lTF8nQR6vk6mBCP5c8Pn9kXL4va37AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Duration action" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Duration action", type duration}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Grouped duration", each if [Duration action]<#duration(0,0,0,31) then "0 - 30 sec" else if [Duration action]<#duration(0,0,1,1) then "30s - 1m" else "etc.")
in
#"Added Custom"
Copy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
Final question 🙂
There are cells which do not contain a duration. This results in an error. How can I prevent the error and keep the Grouped duration empty if the duration action is empty?
Hello @TimR
use this code instead
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TYnJCcBADMR68TsMM/Yewa0Y999G9hFCQB9JVabkYWMuWl9lTF8nQR6vk6mBCP5c8Pn9kXL4va37AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Duration action" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Duration action", type duration}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Grouped duration", each try if [Duration action]<#duration(0,0,0,31) then "0 - 30 sec" else if [Duration action]<#duration(0,0,1,1) then "30s - 1m" else "etc." otherwise null)
in
#"Added Custom"
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
Awesome Jimmy. Many thanks for your prompt reply! This works great
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 19 | |
| 9 | |
| 8 | |
| 7 | |
| 7 |