Live Machine Learning in Azure Stream Analytics-part 2

In last Post, I have explained the process of creating Event Hub, Stream Analytics, and Azure ML model for the aim of applying machine learning to streamed Data. In this post, I will show how to create a function in Stream Analytics for calling the Azure ML API and finally see the result in the Power BI.

Stream Analytics Function

In this stage, we have created an Event Hub, Application to generate random Number, stream analytics and Azure ML model and API to group the streamed data.

In this section, we need to create a function inside Stream Analytics to be able to call the created API in Azure ML. Click on the Azure Stream Analytics job, then click on the Function.

In the creating function page, select the subscription name, the Key and URL extracted from Excel file.

In-Stream Analytics main page, we need to add some code in Query editor to be able to call the function. Click on Edit Query, then in the editor paste the below code

WITH MLStreamAnalytics AS (

SELECT value, MLStreamAnalytics(value) as result

FROM azureml




value, result.[value_quantized]





The first part of the code is for calling the function and get the result from it. As you can see in the below picture, the first part of the code is about the creating a temp table to call the MLStreamAnalytics(value), Then in the next step is about the get the data from Event Hub component (From Azure ML).

The second part of the code about gets the data from a function in azure stream analytics, then pass the data to Power BI component (MLoutput).


Live Analytics on Stream data

The last step is to run the code. First, we need to run the Stream Analytics job by clicking on the Start key.

After running the streaming analytics, open your Power BI service from As you can see below picture, a streamed dataset has been created in Power BI. To work with it click on the report icon and create an empty report.

In the report page, a new Power BI report is shown with on a dataset that has two fields:  Value and Value_quantized.


Need to run the code in.Net application and add the report to the new workspace, after running the code and check the workspace, you able to see the live data coming from the application and the streamed data in Power BI beside the group name and number that each Value is allocated using Azure ML model.

In this post and the last one, an overview of what is Azure Stream Analytics is provided, the different components have been explained briefly. The use case shows how we can leverage it for live analytics using Azure ML model and API has been explained. A sample application to generate a random number has been illustrated, then how we can use Event Hub, Stream Analytics, Azure ML, and Power BI together to show a streamed live data analysis.




Leila Etaati on LinkedinLeila Etaati on TwitterLeila Etaati on Youtube
Leila Etaati
Trainer, Consultant, Mentor
Leila is the first Microsoft AI MVP in New Zealand and Australia, She has Ph.D. in Information System from the University Of Auckland. She is the Co-director and data scientist in RADACAD Company with more than 100 clients in around the world. She is the co-organizer of Microsoft Business Intelligence and Power BI Use group (meetup) in Auckland with more than 1200 members, She is the co-organizer of three main conferences in Auckland: SQL Saturday Auckland (2015 till now) with more than 400 registrations, Difinity (2017 till now) with more than 200 registrations and Global AI Bootcamp 2018. She is a Data Scientist, BI Consultant, Trainer, and Speaker. She is a well-known International Speakers to many conferences such as Microsoft ignite, SQL pass, Data Platform Summit, SQL Saturday, Power BI world Tour and so forth in Europe, USA, Asia, Australia, and New Zealand. She has over ten years’ experience working with databases and software systems. She was involved in many large-scale projects for big-sized companies. She also AI and Data Platform Microsoft MVP. Leila is an active Technical Microsoft AI blogger for RADACAD.

Leave a Reply