Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Team

I am trying to find a way to figure it out as to how to create date although its not on sensors input for my IOT hub. But i want to cater this field as field for my sensors like humidity and temperature. That each sensor needs to have date per dataset for my power bi desktop.

What I have tried:

WITH iot_hub_last_3_mins AS (
    SELECT 
        System.TimeStamp() AS windowTime,
        deviceId,
        max(value) as maxTemp
    FROM
        PowerBIVisualizationOutput TIMESTAMP BY pwb1
    WHERE 
        sensorName = 'IOT Hub' 
    GROUP BY 
        deviceId, 
        SlidingWindow(minute, 3) 
)

SELECT 
    pwb1.t AS eventEnqueuedUctTime,
    pwb1.temperature, 
    pwb1.value AS temp,
	pwb1.maxtTemp AS maxTemp
    
INTO PowerBITable

FROM PowerBIVisualizationInput pwb1 TIMESTAMP BY PowerBIVisualizationOutput
JOIN iot_hub_last_3_mins PowerBIVisualizationOutput
    ON pwb1.temperature = PowerBIVisualizationOutput.deviceId 
    AND pwb1.t = PowerBIVisualizationOutput.windowTime
    AND DATEDIFF(minute,pwb1,PowerBIVisualizationOutput) between 0 and 10
    
WHERE
    pwb1.sensorName = 'temp'
    AND pwb1.value <= 40
    AND PowerBIVisualizationOutput.maxTemp > 10
SELECT 
    pwb1.t AS eventEnqueuedUctTime,
    pwb1.illuminance, 
    pwb1.value AS illum,
	pwb1.maxPower AS maxTemp
    
INTO PowerBITable

FROM PowerBIVisualizationInput pwb1 TIMESTAMP BY PowerBIVisualizationOutput
JOIN iot_hub_last_3_mins PowerBIVisualizationOutput
    ON pwb1.deviceId = PowerBIVisualizationOutput.deviceId 
    AND pwb1.t = PowerBIVisualizationOutput.windowTime
    AND DATEDIFF(minute,t1,t2) between 0 and 3
    
WHERE
    pwb1.sensorName = 'illum'
    AND pwb1.value <= 40
    AND PowerBIVisualizationOutput.maxTemp > 10
Posted
Updated 15-Oct-19 0:36am

One way to do it is to add a Default Values for Columns[^] which can include the date/time the row was inserted. Do that with a UTC default value, and there is no more work needed.
 
Share this answer
 
Hi Team

I managed to have a working around this, but i don't get a data from the date field. My code is as follows; Is there a way can be able to get latest date and timestamp? Please help me i am almost there with this, thanks?

SELECT  
    illuminance as illuminance,
    temperature as temperature,
    MAX(CAST([timeStamp] AS datetime)) AS Date
INTO 
   [PowerBIVisualizationOutput] 
FROM 
   [PowerBIVisualizationInput]
   
GROUP BY 
illuminance,
temperature,
TumblingWindow(minute,5) 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900