Forum Discussion
How to group durations
- 5 years ago
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 - 5 years ago
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
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