(+351) 21 24 10006  ·  info@bconcepts.pt
Carnaxide, Lisbon

Windowed average in Real-Time Analytics: step by step

João Barros 25 de July de 2026 4 min read

This guide shows how to calculate a windowed average in Real-Time Analytics using Azure Stream Analytics and send the results to Power BI. The windowed average technique in Azure Stream Analytics is useful to summarize telemetry (for example, temperature) in fixed intervals and visualize real-time trends.

Prerequisites

  • Azure account with permissions to create resources.
  • An Event Hubs (or IoT Hub) with telemetry events.
  • An Azure Stream Analytics job created (can be in Standard mode).
  • Power BI with a workspace where to create a streaming dataset.

Step 1: Prepare the event source (Event Hubs)

Send JSON events to the Event Hubs with a simple schema: DeviceId, temperature and timestamp. Keep the timestamp in ISO8601 or use the Event Hub time.

{
  "DeviceId": "dev01",
  "temperature": 22.5,
  "timestamp": "2026-07-01T12:00:00Z"
}

If you need to send test events, you can use a small Python script (install azure-eventhub) to package and send a batch:

from azure.eventhub import EventHubProducerClient, EventData

conn_str = ""
eh_name = ""
producer = EventHubProducerClient.from_connection_string(conn_str, eventhub_name=eh_name)

batch = producer.create_batch()
batch.add(EventData('{"DeviceId":"dev01","temperature":22.5,"timestamp":"2026-07-01T12:00:00Z"}'))
producer.send_batch(batch)
producer.close()

Step 2: Create Input and Output in Azure Stream Analytics

In the Azure portal, open your Azure Stream Analytics job and configure:

  • Input: type Event Hub, point to the namespace and the event hub where events arrive.
  • Output: add a Power BI output (choose the workspace and give a name to the dataset/table where results will appear).

Step 3: Write the aggregation query (windowed average)

Use a tumbling window to calculate the average temperature per device in fixed intervals (for example, 1 minute). The query below performs the aggregation and sends it to the configured output.

SELECT
  DeviceId,
  AVG(CAST(temperature AS float)) AS AvgTemp,
  System.Timestamp AS WindowEnd
INTO
  [PowerBIOutput]
FROM
  [EventHubInput] TIMESTAMP BY EventEnqueuedUtcTime
GROUP BY
  DeviceId,
  TumblingWindow(minute, 1)

Quick explanation of what each part does:

  • TIMESTAMP BY EventEnqueuedUtcTime: uses the time the event arrived at Event Hubs (adjust if you have a timestamp field in the payload).
  • TumblingWindow(minute, 1): groups events into consecutive 1-minute windows (non-overlapping).
  • AVG(...) computes the average temperature per device within that window.

Step 4: Map fields and start the job

In the Power BI output, make sure you map the fields DeviceId, AvgTemp and WindowEnd to columns of the streaming dataset. Save the query and start the Stream Analytics job (Start). While the job is running, results begin to be sent to Power BI each window.

Step 5: Visualize in Power BI

In Power BI, create a dashboard with a tile that consumes the streaming dataset. Useful examples:

  • Line chart with WindowEnd on the X axis and AvgTemp on the Y axis (group by DeviceId for multiple series).
  • Card for the latest AvgTemp of a device.

This allows seeing minute-by-minute updates of the calculated averages.

Verify the result

To confirm it's correct:

  • Send test events and observe if they appear in Power BI according to the windows (every minute in the example).
  • In the Azure portal, view the Job Diagram and the Stream Analytics metrics (Input Events, Output Events, Watermark delay) to ensure there are no significant delays.
  • If results are zeros or empty, check the field mapping and whether the JSON names match those used in the query (and if TIMESTAMP BY is correct).

Conclusion

With this basic flow you can calculate windowed averages in real time and visualize them in Power BI. Natural next steps: switch to HoppingWindow for moving averages with overlap, use a timestamp field from the payload for greater accuracy, or apply filtering and anomaly detection. Tip: if you observe latency, check the timestamp used (EventEnqueuedUtcTime vs timestamp in the payload) and adjust the job tolerance.