Forum Discussion
Anonymous
7 years agoNot applicable
Summary Table
Hi I have a table with the following data: Hours Serial Number Failures 20 A 0 15 B 0 ...
- 7 years ago
Hi Anonymous
Try this Power Query /M solution
Please see Query Editor of attached file as well
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjJQ0lFyBGIDpVidaCVDUyDTCc41gckagrnGqIpNkWRjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Hours = _t, #"Serial Number" = _t, Failures = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Hours", Int64.Type}, {"Serial Number", type text}, {"Failures", Int64.Type}}), #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1), #"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each let myindex=[Index] in let mylist= List.Max(Table.SelectRows(#"Added Index",each [Index]<myindex and [Failures]=1)[Index])+1 in if mylist=null then 1 else mylist), #"Grouped Rows" = Table.Group(#"Added Custom", {"Serial Number", "Custom"}, {{"Sum", each List.Sum([Hours]), type number}}), #"Removed Columns" = Table.RemoveColumns(#"Grouped Rows",{"Custom"}) in #"Removed Columns"
Zubair_Muhammad
Community Champion
7 years agoHi Anonymous
Try this Power Query /M solution
Please see Query Editor of attached file as well
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjJQ0lFyBGIDpVidaCVDUyDTCc41gckagrnGqIpNkWRjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Hours = _t, #"Serial Number" = _t, Failures = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Hours", Int64.Type}, {"Serial Number", type text}, {"Failures", Int64.Type}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1),
#"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each let myindex=[Index] in let mylist=
List.Max(Table.SelectRows(#"Added Index",each [Index]<myindex and [Failures]=1)[Index])+1
in
if mylist=null then 1 else mylist),
#"Grouped Rows" = Table.Group(#"Added Custom", {"Serial Number", "Custom"}, {{"Sum", each List.Sum([Hours]), type number}}),
#"Removed Columns" = Table.RemoveColumns(#"Grouped Rows",{"Custom"})
in
#"Removed Columns"