Using Power BI for better analysis of real-time data sent to an IoT Hub

Using Power BI for better analysis of real-time data sent to an IoT Hub

The world around us is changing, largely due to the advancement in technology. As a result of this advancement, a massive amount of data is being generated. Precise prediction and analysis require a large amount of data, which is especially true when using IoT devices and real-time data.

The reason for collecting large amounts of data is often to predict the following outcome or to analyze a particular trend. When we have a large dataset and data flows continuously, it becomes tedious to make analyses and predictions for the data. So, the consequences of this are wrong pattern prediction in the data. Therefore, we can use Power BI to study better real-time data sent to an IoT Hub.

Example: Using Azure IoT Hub and Power BI to analyze temperature and humidity

This blog describes data collection from a simulated IoT device using Azure IoT Hub and forwarding the data from the IoT Hub to Power BI for proper analysis. The data collected from the IoT device comprises of two things – temperature and humidity in the air.

This data is going to be sent after every 10 seconds, so analyzing these metrics in a tabular form would be inefficient and tedious. Therefore, making a visual report to study and analyze the temperature and humidity would be easy and beneficial.

The below snippet shows a sample dataset. The snippet only has 30 rows whereas the dataset that we would be using would contain more than 250 rows. It would be difficult to analyze these metrics simply by looking at the numbers.

Sample dataset - humidity & temperature

There are a total of 4 important components that we are going to make use of:

  • Device: The simulated IoT device would be responsible for sending the data. The data that it would be sending is information about the temperature and humidity.
  • Azure IoT Hub: The hub provides a cloud-hosted solution back end to connect virtually any device. For this experiment, a virtual device would be created in the IoT hub, and that device would be connected to the Simulated IoT device. This would be done to route the messages from the online simulator to the IoT Hub.
  • Azure Stream Analytics: The Stream Analytics is an analytical service that is provided over streaming data. It is important for us because we can draw insights by combining historical data and the streaming data. We can use a query to get the desired output or specific desired rows from the table.
  • Power BI: It is a very useful tool for developing visual reports from various data sources. So, predictions can be made by observing the understandable reports.


IoT Hub with Power BI block diagram

The entire step for creating visual report can be easily broken down into few simple sections.

Creating IoT Hub, setting up the device, and adding Consumer Group

    • We start by creating the IoT Hub in the Azure Portal. You can find the IoT hub in the Azure Marketplace in the portal.

You need to Review+create after filling the details for IoT Hub.

IoT Hub directory

    • After creating the IoT hub, create an IoT Edge device

Creating a device on IoT Hub

    • This edge device is a virtual device, and the primary connection string of this edge device would be responsible for connecting the Online Raspberry Pi Simulator to the IoT hub. In the screenshot below, the primary connection string is visible.

Raspberry pi simulator - IoT Hub

    • In the Online Raspberry Pi Simulator, a script can be seen. In that script connection string copied from the edge device should be updated.
    • A screenshot of the Raspberry Pi Azure IoT Online Simulator after connecting the IoT Edge device to the Simulator. In the bottom right corner, we have sample messages that have been sent to the Azure IoT Hub and the top left corner shows LED Light connected to the Raspberry Pi.

Raspberry Pi Azure IoT online simulator

    •  A screenshot of the messages being to the azure IoT Hub. This message screenshot is taken from the Azure-CLI.

Azure CLI - messages to the IoT hub

    • Consumer Groups are responsible for providing independent views in the event stream also they would be useful for to pull the data from the endpoint. Click the Create new Consumer Group to create one.

Creating new consumer group - IoT Hub

Stream Analytics Job

    • From Azure Marketplace, search for Stream Analytics Job and create it. Here’s a screenshot example:

Creating Stream Analytics job - IoT hub

    • The two most important things need attention: the first one being the input and the second being the output.
    • To configure the input – Inputs need to be selected under the Job Topology. In this case the input would be taken from the Azure IoT Hub. So, you need to enter the information about your IoT Hub. In the screenshot, it is visible that we are selecting IoT Hub from Add stream input. Since IoT Hub has already been created, so it will directly consider the name of the IoT Hub. Input alias must be provided and then easily the Input job will be created after clicking on save option.

Configuring inputs using raspberry pi

    • To configure the output: Outputs needs to be selected under the Job Topology. This is being done to ensure that the data that is passed on from the Azure IoT Hub is sent to the Power BI. Start with filling the details and you can the click on save button.
    • To configure the query: Select query under Job Topology. The query is simple. All you need to do is write your statement according to which you want to filter the data generated from your input source. In the beginning, you can go with the condition WHERE temperature is not null.

Configuring query on stream analytics job

    • After setting up: the inputs, outputs, and the query, you need to simply run the Stream Analytics Job.

Creating and Publishing the Power BI report:

    • Before starting with anything, you need to make sure the online simulator is running fine and is producing outputs.
    • Select the workspace that you have configured in the output of Stream Analytics Job.
    • Hover over the dataset you created while configuring the output of Stream Analytics Job and select create Report options.
    • There are many charts that you can create using the dataset that you have. Set Humidity to Axis and Temperature to Value.

Creating Power BI reports with filters

    • Observe the reports that you created using the charts.
    • Your chart should look like this if you select the stacked area chart format and set everything as defined in the above-mentioned point. You can similarly create many charts using the data that we obtained from the online simulator.

Final temp vs humidity chart

After the experimentation is done, don’t forget to clean up the resources that you have created.


Following the steps described in the blog, we can quickly create detailed reports that would be easy to understand compared to just a large table of values. In addition to this, the large dataset with values and columns becomes challenging to make predictions of an event or a trend. In contrast, trends can be easily predicted using the detailed reports that the Power BI generates.

For an example, in this report it is clearly visible that when the humidity of the place is in the range of 60 to 69 when much noticed rise in the temperature is seen. To make this analysis using the tabular method we would have to go through the entire table one or two times.

I hope you found this tutorial useful to see how Azure IoT Hub and Power BI can be used to improve analysis of real-time data. If you’d like to learn more, I’ve included some references below.