Power BI Advanced Series · Real-Time Streaming · by Raushan Ranjan, MCT
Have you ever wanted your Power BI dashboards to update instantly, reflecting the latest data as it happens? This comprehensive guide will walk you through the entire process of creating a real-time streaming dataset in Power BI Service and feeding it live data using a simple Python script. By the end, you'll have a fully functional, auto-updating dashboard.
✅ PROJECT GOAL:
We will stream temperature, humidity, and timestamp data from Python to Power BI in real-time, and show it on a live dashboard using streaming tiles. This is perfect for IoT monitoring, live sales tracking, or any scenario requiring immediate data visualization.
🔷 PART 1: Create a Streaming Dataset in Power BI
First, let's set up the data stream in Power BI Service.
🔹 Step 1: Go to Power BI Service
- Open your web browser and navigate to: https://app.powerbi.com
- Sign in using your Microsoft Power BI account.
🔹 Step 2: Go to the Workspace
- In the left sidebar, click on Workspaces.
- Choose any existing workspace (e.g., “My Workspace”) or create a new one using the
+ New Workspaceoption.
🔹 Step 3: Create a Streaming Dataset
- Inside your chosen workspace, click
+ New→Streaming dataset. - In the popup that appears, select
APIas the source. - Click
Next.
🔹 Step 4: Define Dataset Schema
This is where you define the structure of the data you'll be sending.
- Enter the field names and data types exactly as follows:
Field Name Data Type temperature Number humidity Number timestamp DateTime - Make sure to toggle Historic data analysis to On. This is crucial if you want to create dashboards or reports that can display historical data from this stream, not just the latest values.
- Click
Create.
🔹 Step 5: Copy the Push URL
After successful creation, Power BI will display a unique Push URL.
- You’ll see a Push URL similar to this:
https://api.powerbi.com/beta/your-dataset-id/rows?key=somekey - Copy this entire URL. We'll use it in our Python script to send data.
🔷 PART 2: Write Python Script to Send Data
Now, let's create the Python script that will generate and send data to your Power BI streaming dataset.
🔹 Step 6: Setup Python Environment
- Ensure you have Python installed on your system. You can download it from python.org.
- Open your terminal (or command prompt on Windows).
- Install the
requestslibrary, which we'll use to send HTTP POST requests:pip install requests
🔹 Step 7: Write Python Script
Understand the below script:
- Create a new Python file, for example,
stream_to_powerbi.py. - Paste the following code into the file. Remember to replace
"https://api.powerbi.com/beta/your-dataset-id/rows?key=your-key-here"with the actual Push URL you copied in Step 5!
import requests
import json
from datetime import datetime
import time
import random
# Replace this with your actual Push URL from Power BI Service (Step 5)
PUSH_URL = "https://api.powerbi.com/beta/your-dataset-id/rows?key=your-key-here"
# Infinite loop to send data every 5 seconds
while True:
# Generate random temperature and humidity data
temperature = round(random.uniform(20.0, 35.0), 2)
humidity = random.randint(40, 90)
timestamp = datetime.now().isoformat() # Get current time in ISO format
# Prepare data as a list of dictionaries (JSON array)
data = [{
"temperature": temperature,
"humidity": humidity,
"timestamp": timestamp
}]
# Send the POST request to Power BI
response = requests.post(PUSH_URL,
data=json.dumps(data),
headers={"Content-Type": "application/json"})
print(f"Sent: {data} | Status: {response.status_code}")
time.sleep(5) # Wait 5 seconds before sending the next data point
🔁 This script sends new random values every 5 seconds. You can adjust the time.sleep() value to change the frequency.
🔷 PART 3: Create a Real-time Dashboard
Now that you have a data stream, let's visualize it in a Power BI dashboard.
🔹 Step 8: Create a Dashboard
- Go back to Power BI Service.
- Inside your workspace, click
+ New→Dashboard. - Name your dashboard (e.g., “IoT Live Monitor”) and click
Create.
🔹 Step 9: Add Real-time Tile to Dashboard
- On your newly created dashboard, click
+ Add tile. - Choose
Custom Streaming Data. - Click
Next.
🔹 Step 10: Choose Dataset and Visual
- Select the streaming dataset you just created (e.g., "IoT_Sensor_Data").
- Click
Next. - Choose the visualization type:
- Line chart – Ideal for showing changes in temperature or humidity over time (e.g.,
timestampon X-axis,temperatureon Y-axis). - Card – To display the latest single value (e.g., current
humidity). - Gauge – For real-time indicators that show a value against a range (e.g.,
temperaturewithin a min/max range).
- Line chart – Ideal for showing changes in temperature or humidity over time (e.g.,
- Bind fields: Drag and drop the fields from your dataset to the appropriate visual roles (Axis, Value, etc.).
- For a line chart:
- Axis:
timestamp - Value:
temperature
- Axis:
- For a card:
- Value:
humidity
- Value:
- For a line chart:
- Click
Next→Apply. - You can add multiple tiles for different metrics (e.g., one line chart for temperature, one for humidity, and a card for the latest timestamp).
🔷 PART 4: Run and Watch It Live
🔹 Step 11: Start Python Script
- Open your terminal or command prompt.
- Navigate to the directory where you saved
stream_to_powerbi.py. - Run the Python script:
python stream_to_powerbi.py - Keep the script running.
- Now, switch back to your Power BI dashboard in the browser. You will see the values on your tiles updating in real time every 5 seconds (or whatever interval you set in your script)!
🧠 EXTRA NOTES:
🧩 How does it work?
- The streaming dataset created in Power BI Service provides a unique public HTTP endpoint (the Push URL).
- Your Python code acts as a data producer, sending JSON data to this endpoint using an HTTP POST request.
- Power BI's streaming engine immediately ingests this data and updates any dashboard tiles that are connected to this specific streaming dataset.
📦 To Modify or Expand:
- Want to stream from real sensors? Replace
random.uniformandrandom.randintin the Python script with actual sensor readings from IoT devices (e.g., via a serial port, MQTT, or a custom API). - Need to store + analyze historical data? By toggling "Historic data analysis" to ON (as we did in Step 4), your streaming dataset also acts as a "Push Dataset," storing data for up to 200,000 rows. You can then create full Power BI reports with filters and slicers on this historical data.
- Want advanced routing and processing? For high-volume or complex real-time data processing, integrate with Azure services like Azure Event Hubs (for ingesting massive streams) and Azure Stream Analytics (for real-time transformations and routing data to Power BI).
Conclusion
You've now successfully built a real-time streaming dashboard in Power BI, powered by Python! This capability is fundamental for modern data solutions, enabling immediate insights and responsive decision-making. Keep experimenting with different data sources and visualizations to unlock even more possibilities for your live dashboards. Happy streaming!
Quick Knowledge Check
Q1. After creating a streaming dataset in Power BI Service, what is the next step to display its data on a dashboard?
Show Answer
Pin a tile from the streaming dataset to a dashboard. Go to Power BI Service → open a dashboard → Add tile → Custom Streaming Data → choose your dataset → configure tile type (line chart, card, gauge) → add to dashboard. Only then will pushed data be visible.
Q2. Your Python streaming script is pushing data but the dashboard tile is not updating. What is the most likely cause?
- A) Python's requests library is not installed
- B) The Push URL in the script does not match the streaming dataset's push URL from Power BI Service
- C) Power BI Service only accepts data from Azure Event Hubs
- D) Dashboard tiles require a manual refresh to display streaming data
Show Answer
B. The push URL is unique to each streaming dataset. If the URL in the script is wrong (wrong dataset ID, API key, or tenant), POST requests return 404 or 401 and no data reaches the dataset. Option C is false — REST API push is fully supported. Option D is false — streaming tiles update automatically.
Q3. What is the purpose of time.sleep(1) in a Python Power BI streaming script?
Show Answer
It controls the push frequency — one data point per second. Without a sleep, the script would push thousands of rows per second, hitting API rate limits. The sleep interval determines tile update frequency: 1s = near-real-time; 5s = every 5 seconds.
- Create dataset first in Service — define the schema before writing Python. Schema cannot be changed after creation without recreating the dataset.
- Push URL is unique and secret — copy it from Power BI Service. It includes the API key; treat it like a password.
- Pin tiles manually — the dataset does not auto-create visuals. Pin a tile from the dataset to a dashboard to see data.
- Control frequency with
time.sleep()— pushing too fast hits rate limits. 1–5 seconds is appropriate for most scenarios. - No SDK needed —
requests.post()with the push URL and JSON body is everything required.