I have a json file as below:
{\"imei\": {\"imei\": \"358174069248418F\", \"imeiBinary\": \"NYF0BpJIQY8=\",\"imeiNotEncoded\": \"358174069248418\",\"va
According to https://msdn.microsoft.com/en-us/library/mt598501.aspx TIMESTAMP BY can only be used on input sources, so you would want to put that as part of your very first step:
WITH Datapackets AS
...
FROM h24 TIMESTAMP BY (expression)
...
Furthermore, from the same source, referring to System.TimeStamp when used with a GROUP BY over a window:
The timestamp of the result of the aggregate is the end of the time window to which this result corresponds.
So when you write System.TimeStamp in the final SELECT statement, it refers to the end of the current window.