You are currently viewing How to make Streaming Dashboard in PowerBI

How to make Streaming Dashboard in PowerBI

Loading

In this blog you will learn about how to create a Streaming dashboard in PowerBI. You will generating data with the help of Python code.

What is Streaming Dashboard in PowerBI

Streaming Dashboard is a type of dashboard that updates in real-time and near real-time. So we can find live insights with continues data update.

Use Case of Streaming Dashboard in PowerBI

In Healthcare:

  • Monitoring patient vital
  • ER wait times

In Stock

  • Tracking real-time stock prices, trading volumes and transaction analytics

In Retail and E-commerce

  • Live sales data monitoring
  • Customer Interactions

Prerequisites:

Software & Libraries:

  • Web Browser (recommended- Chrome)
  • Python (>=3.0)
  • pandas
  • requests
  • flask

General:

  • Microsoft Account

Steps to creating Streaming Dashboard in PowerBI

Step 1: Open Browser (e.g. Chrome)

Step 2: Go to URL section and type – https://app.powerbi.com

Step 3: Sign In with your Microsoft Account

Step 4: Click on Workspaces and select your workspace.

Step 5: Select your workspace (click on New workspace, if you haven’t)

Step 6: Click on New and select Streaming dataset

Step 7: Select API and click on Next

Note:

  • You can select AZURE STREAM and PUBNUB also (as your requirements)

Step 8: Fill the following details and click on Create

Step 9: Copy/Save Push URL somewhere and click on Done

Step 10: Click on New and select Dashboard

Step 11: Give a name for Dashboard and click on Create

Step 12: Click on Edit and select Add a tile

Step 13: select Custom Streaming Data and click on Next

Step 14: Select Streaming Dataset that we created earlier (Step 6 – 9)

Step 15: Place the following and click on Next:

Visualization type

Clustered column chart

Axis

Item

Values

Qty

Time window to display

5 Minutes

Step 16: Click on Apply

Step 17: Again click on Edit and select Add a tile

Step 18: select Custom Streaming Data and click on Next

Step 19: Select Streaming Dataset that we created earlier (Step 6 – 9)

Step 20: Place the following and click on Next:

Visualization type

Card

Fields

Qty

Step 21: Click on Apply

Step 22: Again click on Edit and select Add a tile

Step 23: select Custom Streaming Data and click on Next

Step 24: Select Streaming Dataset that we created earlier (Step 6 – 9)

Step 25: Place the following and click on Next:

Visualization type

Card

Axis

Unit Price

Step 26: Click on Apply

Step 27: Again click on Edit and select Add a tile

Step 28: select Custom Streaming Data and click on Next

Step 29: Select Streaming Dataset that we created earlier (Step 6 – 9)

Step 30: Place the following and click on Next:

Visualization type

Line chart

Axis

Time

Values

Total Price

Time window to display

5 Minutes

Step 31: Click on Apply

Step 32: Final look of visual:

Now, we have to post the data to power bi.

For posting the data to power bi, we can use website, normal python script and etc.

Step 33: create a file named app.py and type/paste the following:

from flask import Flask, render_template, request, redirect, url_for
import pandas as pd
import requests
import datetime

app = Flask(__name__)

POWERBI_API_URL = 'https://api.powerbi.com/beta/2023ead0-1aa4-4505-85ef-5235ede65441/datasets/b6d26984-e72a-4bca-a396-10c3dcaa4d27/rows?experience=power-bi&clientSideAuth=0&key=sAkLzDQ5LRHa6qU%2FmfVsCcW0S1GTgPwp6wUvBHRFCPzSSyzfRexrhmlB3V88m8p651SLQMYnItuisJw8Yn%2BR1A%3D%3D'

def calculate_total_price(qty, unit_price):
    return qty * unit_price

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/submit', methods=['POST'])
def submit():
    user_id = request.form['userId']
    item = request.form['item']
    qty = int(request.form['qty'])
    unit_price = float(request.form['unit_price'])
    total_price = calculate_total_price(qty, unit_price)
    date = datetime.datetime.today().strftime("%Y-%m-%d")
    time = datetime.datetime.now().isoformat()

    data_raw = [[user_id, item, qty, unit_price, total_price, date, time]]

    HEADER = ["userId", "Item", "Qty", "Unit Price", "Total Price", "Date", "Time"]

    data_df = pd.DataFrame(data_raw, columns=HEADER)
    data_json = bytes(data_df.to_json(orient='records'), encoding='utf-8')
    print("JSON dataset", data_json)

    # Post the data on the Power BI API
    req = requests.post(POWERBI_API_URL, data_json)
    print("Data posted in Power BI API")

    return redirect(url_for('index'))

if __name__ == '__main__':
    app.run(debug=True)

Step 34: create a file named index.html in templates folder and type/paste the following:

<!DOCTYPE html>
<html>
<head>
    <title>Sales Data Input</title>
    <style>
		*{
		    margin: 0;
			box-sizing: border-box;
			outline: none;
		}
		body{
			background: #dddcdc;
		}
		div{
			padding: 20px;
			position: absolute;
			top: 50%;
			left: 50%;
			transform: translate(-50%, -50%);
			background: #c4c4c4;
			border-radius: 4px;
		}
		h1{
			text-align: center;
			color: #055d65;
		}
		form{
			padding: 10%;
		}
		label{
    		display: inline-block;
    		color: #055d65;
    		font-weight: bold;
		}
		input[type="text"],input[type="number"],select{
    		padding: 8px;
    		margin-bottom: 10px;
    		border: 1px solid #ccc;
    		border-radius: 4px;
    		box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
		}
		input[type="submit"]{
		    width: 100%;
		    background-color: #055d65;
		    color: white;
		    border: none;
		    padding: 10px 15px;
		    cursor: pointer;
		    border-radius: 4px;
		}
		input[type="submit"]:hover{
		    background-color: #004e55;
		}
    </style>
</head>
<body>
	<div>
		<h1>Enter Sales Data</h1>
    	<form action="/submit" method="post">
    	    <label for="userId">User ID:</label><br>
    	    <input type="text" id="userId" name="userId"><br><br>
    	    <label for="item">Item:</label><br>
			<select name="item" id="item" onchange="itemprice();">
			    <option selected disabled>Select an Item</option>
			    <option value="CPU">CPU</option>
			    <option value="Keyboard">Keyboard</option>
			    <option value="Laptop">Laptop</option>
			    <option value="Monitor">Monitor</option>
			    <option value="Mouse">Mouse</option>
			    <option value="UPS">UPS</option>
			</select><br><br>
    	    <label for="qty">Quantity:</label><br>
    	    <input type="number" id="qty" name="qty"><br><br>
    	    <label for="unit_price" >Unit Price:</label><br>
    	    <input type="number" step="0.01" id="unit_price" name="unit_price"><br><br>
    	    <input type="submit" value="Submit">
    	</form>
	</div>

    <script>
	var item = document.querySelector("#item");
	var unit_price = document.querySelector("#unit_price");
	function itemprice(){
	    switch (item.value){
		case "CPU":
		    unit_price.value = 2500;
		    break;
		case "Keyboard":
		    unit_price.value = 1299;
		    break;
		case "Laptop":
		    unit_price.value = 52000;
		    break;
		case "Monitor":
		    unit_price.value = 7900;
		    break;
		case "Mouse":
		    unit_price.value = 490;
		    break;
		case "UPS":
		    unit_price.value = 4999;
		    break;
		default:
		    unit_price.value = 0;
		    break;
	    }
	}
    </script>
</body>
</html>

Step 35: Run app.py in command prompt with following command:

python app.py

Note:

  • You will get a development url: http://127.0.0.1:5000

Step 36: Run URL on any web browser and put some entries:

Conclusion

Streaming dashboards in Power BI provide a robust solution for real-time data visualization and decision making. By seamlessly connecting to various data sources and enabling automatic updates, these dashboards ensure that users always have the latest information. Whether it’s monitoring operational data, financial data, or IoT device output, streaming dashboards enable organizations to quickly respond to changes, identify emerging trends, and maintain strong situational awareness. As the need for real-time information grows, leveraging Power BI’s streaming capabilities can provide significant benefits to businesses in today’s fast-paced, data-driven world.

If you like the article and would like to support me, make sure to:

Leave a Reply