[{"id":"840f0737-df1d-47ae-bb0a-359b01fe0608","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"d5d9cdef-8854-4505-89be-a2bbc3cb4482","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"3dc3dd55-35b0-4d23-bf62-47bc3650e4ee","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"80d84fbc-d0f8-4e4a-947f-e3e4de9b49b2","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"9152b7ca-0186-4fe3-a26f-5a05f322db07","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]}]
        
(Showing Draft Content)

任意时间段的差值分析

需求描述

在智能用电中,每个电表的用电量记录都是按频率收集的。

例如,收集频率是每 10分钟一次(可能以秒、分钟和小时为单位)。分析时,需要统计这个时间范围内的用电量(结束时间用电量减去开始时间用电量),会按照小时、日、月、年等不同维度进行显示。

在仪表板中实现

原有统计数据示例如下,每十分钟统计一次。

image2021-12-17_14-43-24.png

实际每个时间段的用电量需要用下一行的数据减去当前行。

这里我们需要创建一个数据列,使每一行都返回数据。用窗口函数 LEADW拿到下一行的数据,然后再减去当前数据。

image2021-12-17_15-4-21.png

image

LEADW(
    null,
    'GrapecityElectricityData_Direct'[Electricity Value],
    PARTITIONBY(
        'GrapecityElectricityData_Direct'[Device ID]
        ),
    ORDERBY(
        'GrapecityElectricityData_Direct'[Collection DateTime]
        )
    )
-
'GrapecityElectricityData_Direct'[Electricity Value]

绑定实际用电量,可见每一行得到的都是下一行的值减去当前行。

image2021-12-17_14-59-14.png

这样就得到了每一个10分钟的用电量,后续可使用该数据进行按天,月等维度进行统计。(下图中的 leadwcal 即实际用电量)

image2021-12-17_15-2-6.png

type=info

提示

使用 leadw 进行计算时会存在一定误差,因为最后一行在计算时没有下一行来参与运算,所以无法正确返回结果。

image2021-12-17_15-6-24.png