let
Source = Folder.Files("Z:\campbell_diagnostics"),
#"Filtered Rows1" = Table.SelectRows(Source, each Text.Contains([Name], "Bat")),
#"Added Custom" = Table.AddColumn(#"Filtered Rows1", "Custom", each [Content]),
#"Filtered Hidden Files1" = Table.SelectRows(#"Added Custom", each [Attributes]?[Hidden]? <> true),
#"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File from Diagnostics", each #"Transform File from Diagnostics"([Custom])),
#"Removed Columns" = Table.RemoveColumns(#"Invoke Custom Function1",{"Content", "Extension", "Date accessed", "Date modified", "Date created", "Attributes", "Folder Path", "Custom"}),
#"Expanded Transform File from Diagnostics" = Table.ExpandTableColumn(#"Removed Columns", "Transform File from Diagnostics", {"Column1", "Column3"}, {"Transform File from Diagnostics.Column1", "Transform File from Diagnostics.Column3"}),
#"Filtered Rows" = Table.SelectRows(#"Expanded Transform File from Diagnostics", each Text.Contains([Transform File from Diagnostics.Column1], ":00")),
#"Changed Type1" = Table.TransformColumnTypes(#"Filtered Rows",{{"Transform File from Diagnostics.Column3", type number}}),
#"Pivoted Column" = Table.Pivot(#"Changed Type1", List.Distinct(#"Changed Type1"[Name]), "Name", "Transform File from Diagnostics.Column3"),
#"Renamed Columns1" = Table.RenameColumns(#"Pivoted Column",{{"Transform File from Diagnostics.Column1", "Date"}}),
#"Replaced Value2" = Table.ReplaceValue(#"Renamed Columns1","00:00:00","",Replacer.ReplaceText,{"Date"}),
#"Replaced Value" = Table.ReplaceValue(#"Replaced Value2",null,0,Replacer.ReplaceValue,Table.ColumnNames(#"Replaced Value2")),
#"Changed Type" = Table.TransformColumnTypes(#"Replaced Value",{{"Date", type date}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Date"}, "Attribute", "Value"),
#"Replaced Value3" = Table.ReplaceValue(#"Unpivoted Columns","_Battery_Level.dat"," ",Replacer.ReplaceText,{"Attribute"}),
#"Sorted Rows" = Table.Sort(#"Replaced Value3",{{"Date", Order.Descending}, {"Value", Order.Ascending}}),
#"Pivoted Column1" = Table.Pivot(#"Sorted Rows", List.Distinct(#"Sorted Rows"[Attribute]), "Attribute", "Value", List.Sum),
#"Filtered Rows2" = Table.SelectRows(#"Pivoted Column1", let latest = List.Max(#"Pivoted Column1"[Date]) in each Date.IsInPreviousNDays([Date], 30) or [Date] = latest),
#"Replaced Value1" = Table.ReplaceValue(#"Filtered Rows2",0,null,Replacer.ReplaceValue,Table.ColumnNames(#"Filtered Rows2"))
in
#"Replaced Value1"