基本上,我每隔几秒钟就会收到来自传感器的数据。我正在尝试找到一种方法:
我正在PowerBI桌面上工作,不确定如何在DAX或查询编辑器中执行此操作。有什么想法吗?
答案 0 :(得分:0)
很抱歉这么晚才回答。不知道这是否仍然有用。
这里是一个示例,其中使用索引为每个连续的传感器读数块分配一个递增的索引号。可以通过在您希望描述的任何时间段上对该索引进行不同的计数来获得读数计数。
在这里,我已经模拟了每3秒获取的数十万个读数,其中传感器“开”表示5个读数,“开”表示5个读数。
请注意,颗粒数和合计数之间存在一定的滑移,这是周期跨周期中断的结果。
这是我用于参考的M查询。希望对您有所帮助。
let
Source = Excel.Workbook(File.Contents("C:\Users\*****\Desktop\Book2.xlsx"), null, true),
Table1_Table = Source{[Item="Table1",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(Table1_Table,{{"Date", type date}, {"Time", type time}}),
#"Sorted Rows" = Table.Sort(#"Changed Type",{{"Date", Order.Ascending},{"Time", Order.Ascending}}),
#"ShiftList" = {""} & List.RemoveLastN(Table.Column(#"Sorted Rows","Sensor Reading"),1),
#"ColumnsAndShift" = Table.ToColumns(#"Sorted Rows") & {ShiftList},
#"ResultSet" = Table.FromColumns(#"ColumnsAndShift", Table.ColumnNames(#"Sorted Rows") & {"Previous Reading"}),
#"Filtered Rows" = Table.SelectRows(ResultSet, each ([Previous Reading] = "")),
#"Filtered Rows1" = Table.SelectRows(#"Filtered Rows", each [Sensor Reading] <> ""),
#"Added Index" = Table.AddIndexColumn(#"Filtered Rows1", "Index", 1, 1),
#"Merged Queries" = Table.NestedJoin(#"ResultSet",{"Date", "Time"},#"Added Index",{"Date", "Time"},"Added Index",JoinKind.LeftOuter),
#"Expanded Added Index" = Table.ExpandTableColumn(#"Merged Queries", "Added Index", {"Index"}, {"Added Index.Index"}),
#"Sorted Rows1" = Table.Sort(#"Expanded Added Index",{{"Date", Order.Ascending}, {"Time", Order.Ascending}}),
#"Filled Down" = Table.FillDown(#"Sorted Rows1",{"Added Index.Index"}),
#"Added Conditional Column" = Table.AddColumn(#"Filled Down", "Cycle Index", each if [Sensor Reading] <> "" then [Added Index.Index] else ""),
#"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column",{"Previous Reading", "Added Index.Index"})
in
#"Removed Columns"