QuickSight calculated field: How to get sum of last values of timestream measures

0

Hi,

I have a TimeStream table containing power consumed by IoT devices. I would like to create a calculated field in QuickSight which computes the sum of last power values reported by all devices?

AWS
질문됨 2년 전1619회 조회
1개 답변
0

If I understand correctly, the query result is a single value which represents the aggregate power of all devices. The device values to aggregate is the latest power of each device. For e.g. if there are 3 devices with the following power values

device1: 00:00:00 val=20, 00:00:05 val=25, 00:00:10 val=20
device2: 00:00:00 val=19, 00:00:05 val=72, 00:00:10 val=81
device3: 00:00:00 val=00, 00:00:05 val=22, 00:00:10 val=100

The result will be (20 + 81 + 100) = 201

A sample query for this is below

WITH cte1 AS (
    SELECT device, first_value(measure_value::bigint) OVER (PARTITION BY device ORDER BY time DESC) as value FROM <db>.<table> WHERE time > ago(1m)
), cte2 AS (
   SELECT device, min(value) as value FROM cte1 GROUP BY device
) SELECT sum(value) FROM cte2

The time predicate e.g. ago(1m) is necessary to ensure that the whole table is not scanned. It can be set to any time window that will give the latest power values of all devices.

AWS
답변함 2년 전
  • Thanks Rajesh! I was thinking of doing this via introducing a calculated fields on quicksight? Is this use case supported?

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠