Tutorial: Visualize real-time sensor data from Azure IoT Hub using Power BI

You can use Microsoft Power BI to visualize real-time sensor data that your Azure IoT hub receives. To do so, you configure an Azure Stream Analytics job to consume the data from IoT Hub and route it to a dataset in Power BI.

End-to-end diagram

Microsoft Power BI is a data visualization tool that you can use to perform self-service and enterprise business intelligence (BI) over large data sets. Azure Stream Analytics is a fully managed, real-time analytics service designed to help you analyze and process fast moving streams of data that can be used to get insights, build reports or trigger alerts and actions.

In this tutorial, you perform the following tasks:

  • Create a consumer group on your IoT hub.
  • Create and configure an Azure Stream Analytics job to read temperature telemetry from your consumer group and send it to Power BI.
  • Create a report of the temperature data in Power BI and share it to the web.

Prerequisites

  • Complete the one of the Send telemetry quickstarts in the development language of your choice. Alternatively, you can use any device app that sends temperature telemetry; for example, the Raspberry Pi online simulator or one of the Embedded device quickstarts. These articles cover the following requirements:

    • An active Azure subscription.
    • An Azure IoT hub in your subscription.
    • A client app that sends messages to your Azure IoT hub.
  • A Power BI account. (Try Power BI for free)

Add a consumer group to your IoT hub

Consumer groups provide independent views into the event stream that enable apps and Azure services to independently consume data from the same Event Hub endpoint. In this section, you add a consumer group to your IoT hub's built-in endpoint that is used later in this tutorial to pull data from the endpoint.

To add a consumer group to your IoT hub, follow these steps:

  1. In the Azure portal, open your IoT hub.

  2. On the left pane, select Built-in endpoints. Enter a name for your new consumer group in the text box under Consumer groups.

    Screenshot showing how to create a consumer group in your IoT hub.

  3. Click anywhere outside the text box to save the consumer group.

Create, configure, and run a Stream Analytics job

Let's start by creating a Stream Analytics job. After you create the job, you define the inputs, outputs, and the query used to retrieve the data.

Create a Stream Analytics job

  1. In the Azure portal, select Create a resource. Type Stream Analytics Job in the search box and select it from the drop-down list. On the Stream Analytics job overview page, select Create

  2. In the Basics tab of the working pane, enter the following information.

    Subscription: Select the subscription for your IoT hub.

    Resource group: Select the resource group for your IoT hub.

    Name: Enter the name of the job. The name must be globally unique.

    Region: Select the region for your IoT hub.

    Leave all other fields at their defaults, as shown in the following picture.

    Create a Stream Analytics job in Azure

  3. Select Review + create, then select Create to create the Stream Analytics job.

Add an input to the Stream Analytics job

  1. Open the Stream Analytics job.

  2. Under Job topology, select Inputs.

  3. In the Inputs pane, select Add stream input, then select IoT Hub from the drop-down list. On the new input pane, enter the following information:

    Input alias: Enter a unique alias for the input.

    Select IoT Hub from your subscription: Select this radio button.

    Subscription: Select the Azure subscription you're using for this tutorial.

    IoT Hub: Select the IoT hub you're using for this tutorial.

    Consumer group: Select the consumer group you created previously.

    Shared access policy name: Select the name of the shared access policy you want the Stream Analytics job to use for your IoT hub. For this tutorial, you can select service. The service policy is created by default on new IoT hubs and grants permission to send and receive on cloud-side endpoints exposed by the IoT hub. To learn more, see Access control and permissions.

    Shared access policy key: This field is automatically filled, based on your selection for the shared access policy name.

    Endpoint: Select Messaging.

    Leave all other fields at their defaults, as shown in the following picture.

    Add an input to a Stream Analytics job in Azure

  4. Select Save.

Add an output to the Stream Analytics job

  1. Under Job topology, select Outputs.

  2. In the Outputs pane, select Add, and then select Power BI from the drop-down list.

  3. On the Power BI - New output pane, select Authorize and follow the prompts to sign in to your Power BI account.

  4. After you've signed in to Power BI, enter the following information:

    Output alias: A unique alias for the output.

    Group workspace: Select your target group workspace.

    Dataset name: Enter a dataset name.

    Table name: Enter a table name.

    Authentication mode: Leave at the default.

    Add an output to a Stream Analytics job in Azure

  5. Select Save.

Configure the query of the Stream Analytics job

  1. Under Job topology, select Query.

  2. Replace [YourInputAlias] with the input alias of the job.

  3. Replace [YourOutputAlias] with the output alias of the job.

  4. Add the following WHERE clause as the last line of the query. This line ensures that only messages with a temperature property will be forwarded to Power BI.

    WHERE temperature IS NOT NULL
    
  5. Your query should look similar to the following screenshot. Select Save query.

    Add a query to a Stream Analytics job

Run the Stream Analytics job

In the Stream Analytics job, select Overview, then select Start > Now > Start. Once the job successfully starts, the job status changes from Stopped to Running.

Run a Stream Analytics job in Azure

Create and publish a Power BI report to visualize the data

The following steps show you how to create and publish a report using the Power BI service. You can follow these steps, with some modification, if you want to use the "new look" in Power BI. To understand the differences and how to navigate in the "new look", see The 'new look' of the Power BI service.

  1. Make sure the client app is running on your device.

  2. Sign in to your Power BI account and select Power BI service from the top menu.

  3. Select the workspace you used from the side menu, My Workspace.

  4. Under the All tab or the Datasets + dataflows tab, you should see the dataset that you specified when you created the output for the Stream Analytics job.

  5. Hover over the dataset you created, select More options menu (the three dots to the right of the dataset name), and then select Create report.

    Create a Microsoft Power BI report

  6. Create a line chart to show real-time temperature over time.

    1. On the Visualizations pane of the report creation page, select the line chart icon to add a line chart. Use the guides located on the sides and corners of the chart to adjust its size and position.

    2. On the Fields pane, expand the table that you specified when you created the output for the Stream Analytics job.

    3. Drag EventEnqueuedUtcTime to Axis on the Visualizations pane.

    4. Drag temperature to Values.

      A line chart is created. The x-axis displays date and time in the UTC time zone. The y-axis displays temperature from the sensor.

      Add a line chart for temperature to a Microsoft Power BI report

    Note

    Depending on the device or simulated device that you use to send telemetry data, you may have a slightly different list of fields.

  7. Select File > Save to save the report. When prompted, enter a name for your report. When prompted for a sensitivity label, you can select Public and then select Save.

  8. Still on the report pane, select File > Embed report > Website or portal.

    Select embed report website for the Microsoft Power BI report

    Note

    If you get a notification to contact your administrator to enable embed code creation, you may need to contact them. Embed code creation must be enabled before you can complete this step.

    Contact your administrator notification

  9. You're provided the report link that you can share with anyone for report access and a code snippet that you can use to integrate the report into a blog or website. Copy the link in the Secure embed code window and then close the window.

    Copy the embed report link

  10. Open a web browser and paste the link into the address bar.

    Publish a Microsoft Power BI report

Microsoft also offers the Power BI mobile apps for viewing and interacting with your Power BI dashboards and reports on your mobile device.

Clean up resources

In this tutorial, you've created a resource group, an IoT hub, a Stream Analytics job, and a dataset in Power BI.

If you plan to complete other tutorials, you may want to keep the resource group and IoT hub, so you can reuse them later.

If you don't need the IoT hub or the other resources you created any longer, you can delete the resource group in the Azure portal. To do so, select the resource group and then select Delete resource group. If you want to keep the IoT hub, you can delete other resources from the Overview pane of the resource group. To do so, right-click the resource, select Delete from the context menu, and follow the prompts.

Use the Azure CLI to clean up Azure resources

To remove the resource group and all of its resources, use the az group delete command.

az group delete --name {your resource group}

Clean up Power BI resources

You created a dataset, PowerBiVisualizationDataSet, in Power BI. To remove it, sign in to your Power BI account. On the left-hand menu under Workspaces, select My workspace. In the list of datasets under the DataSets + dataflows tab, hover over the PowerBiVisualizationDataSet dataset. Select the three vertical dots that appear to the right of the dataset name to open the More options menu, then select Delete and follow the prompts. When you remove the dataset, the report is removed as well.

Next steps

In this tutorial, you learned how to use Power BI to visualize real-time sensor data from your Azure IoT hub by performing the following tasks:

  • Create a consumer group on your IoT hub.
  • Create and configure an Azure Stream Analytics job to read temperature telemetry from your consumer group and send it to Power BI.
  • Configure a report for the temperature data in Power BI and share it to the web.

For another way to visualize data from Azure IoT Hub, see the following article.