Forum Discussion
Anonymous
2 years agoNot applicable
Calculating Mean Time Between Failure
@Amit, @Greg , @tamerj1 , @lbendlin @amitchandak , @olgad , @Sahir_Maharaj , @FreemanZ , @tamerj1 , @Greg_Deckler @christinepayton @audreygerred LukeB, Hello PowerBI expert folks, ...
Anonymous
2 years agoNot applicable
Hello lbendlin ,
I have attached the sample file. Please let me know how you would implement your code in this sample data or if you have any other questions.
Thanks
| Equipment | BreakDownDate | Index | |||
| Halt-F16 | 01/05/2023 3:39:00 AM | 1 | |||
| Halt-F16 | 01/05/2023 12:42:00 AM | 2 | |||
| Halt-F16 | 01/10/2023 2:55:00 AM | 3 | |||
| Halt-F17 | 01/11/2023 4:01:00 AM | 4 | |||
| Halt-F18 | 01/17/2023 12:00:00 PM | 5 | |||
| Fault-F35 | 01/17/2023 10:12:00 PM | 6 | |||
| Fault-F35 | 01/18/2023 1:58:00 AM | 7 |
lbendlin
2 years agoSuper User
Your sample data is incorrect. Row 2 happens before Row 1.
Please provide usable sample data.
- Anonymous2 years agoNot applicable
- lbendlin2 years agoSuper User
let Source = Table.FromRows( Json.Document( Binary.Decompress( Binary.FromText( "fc+7CoQwEAXQXwmpFe9MHI3TbSM2wvZiYb+l/r/IhCDq2h/uY5r8sPzWsqfGFx5UQSoGBxc0dAq4z+j8XPxTxFrzwb7jgyKYYhWxrDNqEyJDtYLuKLqk2lwIWKHt6pftgEEuDkr85mJyKjHfnHc=", BinaryEncoding.Base64 ), Compression.Deflate ) ), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Equipment = _t, BreakDownDate = _t] ), #"Changed Type" = Table.TransformColumnTypes( Source, {{"Equipment", type text}, {"BreakDownDate", type datetime}} ), #"Grouped Rows" = Table.Group( #"Changed Type", {"Equipment"}, { { "Rows", each Table.AddIndexColumn(_, "Index", 0, 1, Int64.Type), type table [ Equipment = nullable text, BreakDownDate = nullable datetime, Index = Int64.Type ] } } ), #"Added Custom1" = Table.AddColumn( #"Grouped Rows", "NewRows", (k) => Table.AddColumn( k[Rows], "MTBF", each if [Index] = 0 then null else [BreakDownDate] - k[Rows]{[Index] - 1}[BreakDownDate], type duration ) ), #"Expanded NewRows" = Table.ExpandTableColumn( #"Added Custom1", "NewRows", {"BreakDownDate", "MTBF"}, {"BreakDownDate", "MTBF"} ), #"Removed Other Columns" = Table.SelectColumns( #"Expanded NewRows", {"Equipment", "BreakDownDate", "MTBF"} ), #"Changed Type1" = Table.TransformColumnTypes( #"Removed Other Columns", {{"BreakDownDate", type datetime}, {"MTBF", type duration}} ) in #"Changed Type1"How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.