Power BI Tutorial - Sentiment Analysis

In this article, we’ll learn about enriching data with Power BI using the Azure Cognitive Services. We’ll get a brief intro to Azure Cognitive Service and Power BI and dive into a hands-on experience to use a simple CSV file that contains data of News, transform it and with the power of Azure Cognitive Services that is integrated within Power BI now, perform sentiment analysis on the data to find out the Positivity or Negativity of the News. Lastly, we’ll visualize this data in regard to the topic which will showcase the sentiment based on the headline of the news.

Azure Cognitive Services

Azure Cognitive Services is one of the services offered by Microsoft Azure that enables a wide range of organizations to build cognitive intelligence for applications with client library SDKs and REST APIs. Azure Cognitive Services allows developers to integrate cognitive features into applications with no prior knowledge of Machine Learning, Data Science, and Artificial Intelligence skillset. From Computer Vision to Natural Language Processing and Conversational AI, Azure Cognitive Services provides the support for a diverse prospect of applications.

To learn more about Azure Cognitive Services, read this article, Azure Cognitive Services which explains the services provided by Azure dedicated for Machine Learning and Artificial Intelligence in detail.

Power BI

Power BI is a tool provided by Microsoft which is dedicated to enabling business analytics and intelligence capabilities for any organization with interactive visualizations with a minimalistic interface that is extremely convenient to use for the end-users in order to create their own dashboards and reports. Microsoft Power BI is a part of the Microsoft Power Platform ecosystem.

Power BI focuses on creating a data-centric culture for business intelligence that allows organizations to produce powerful outcomes by listening to the data and empowering them with the tools to support decision-making.

Power BI can be accessed and used in primarily two ways. One through the Power BI Desktop application and another through the web application of Power BI. Moreover, Power BI offers three different possibilities, one as the Power BI Pro which uses the power of the cloud in order to share reports and collaborate. For enterprises, it offers the Power BI Premium which provides advanced analytics that can be scaled as per the need. Furthermore, the Power BI Mobile version helps one work on the free Power BI Mobile using Android and iOS devices.

In this article, we’ll merge the power of these two amazing tools – the Microsoft Cognitive Services and Microsoft Power BI and see what we can make out of it.

Step 1

Let us start with logging in to Power BI and installing the Power BI Desktop app.

Currently, there are a few Azure Cognitive Services features integrated into Power BI under the Premium License. 

Power BI Tutorial: Sentiment Analysis

Click on the AI Insights, and we can find the 4 services that are available which are Tag Images, Extract key phrases, Detect Language, and Score Sentiment.

Step 2

Now, let us go to the Power BI Service and Create a Workspace.

Power BI Tutorial: Sentiment Analysis

Step 3

Fill in the Workspace Name. Here we are using New_demo as the workspace name as the data we are using is from News.

Power BI Tutorial: Sentiment Analysis

Step 4

Since the cognitive service integration is available only through the premium license, we choose the license mode of Premium per user. Rest would be all default settings.

Power BI Tutorial: Sentiment Analysis

Step 5

Now the Workspace has been created. It basically contains all of our dashboards, reports, data flows, and more. It works as a container for all the features.

Power BI Tutorial: Sentiment Analysis

Step 6

We now need to create a data flow. Data Flow in Power BI can be understood as the collection of tables and can be used to manage the tables and to transform our data.

Power BI Tutorial: Sentiment Analysis

Step 7

Now, Click on Add New Tables.

Power BI Tutorial: Sentiment Analysis

Step 8

We can see numerous data sources from which data can be made available. We currently will use a text/CSV.

Power BI Tutorial: Sentiment Analysis

Step 9

Now, we can just copy and paste the URL of the CSV file or browse it from the OneDrive.

Power BI Tutorial: Sentiment Analysis

Step 10

Now, the data is loaded and ready to be transformed.

 Power BI Tutorial: Sentiment Analysis

Now, click on Transform Data.

Step 11

Here, the Power BI didn’t recognize the first row which contained data such as Title, Headline, was Headings, Source, and Topic.

Power BI Tutorial: Sentiment Analysis

So, to fix this, click on the Table icon and select Use first rows as headers.

Power BI Tutorial: Sentiment Analysis

You can see the change now. The first row has now been changed into a header.

Power BI Tutorial: Sentiment Analysis

Step 12

Now, we can see how the sentiment of the news is distributed with respect to the topic. For this, we’ll use the feature from Azure Cognitive Service. So, let us select AI Insights.

Power BI Tutorial: Sentiment Analysis

Step 13

Since we want the sentiment of the news, we’ll use Score Sentiment. 

Power BI Tutorial: Sentiment Analysis

Step 14

We want to pass the Headline of the news as a value, we’ll select the Use values in a column such that the sentiment of the news will be derived from the Headline.

Power BI Tutorial: Sentiment Analysis

Power BI Tutorial: Sentiment Analysis

Now, Click on Apply. 

Step 15

Azure will take a swift amount of time and create a new column named CognitiveServices.ScoreSentiment which now contains the sentiment value of the news. This was performed by the use of the Azure Cognitive Services - Score Sentiment feature which is integrated into the premium version of Power BI. Here, in the backend, the Power BI will make an API call by itself to Azure Cognitive Services Text Analysis Model which will return the Score Sentiment value on the Power BI automatically.

Power BI Tutorial: Sentiment Analysis

Step 16

We can see, the values are between 0 and 1.

The closer the Sentiment value is to 1- it can be recognized as more Positive News and the closer the sentiment of the news is to 0, it can be understood are more negative.

If you want to learn more about Azure watch this video from our Azure Summit 2021. 

Step 17

Now, let us add a Conditional Column to make this outcome more intuitive.

Let us suppose if the sentiment value is above 0.5 the News is Positive, 0.5 precise as Neutral and below 0.5 as Negative.

Power BI Tutorial: Sentiment Analysis

Once, the new column is created, Save the Data. 

Step 18

Now, let us save the data flow as news_data. 

Power BI Tutorial: Sentiment Analysis

Step 19

Now, let us go to Power BI Desktop, and obtain the Data as Power BI Dataflows. This is going to connect to the Power BI service. Hence, use the same credentials in the Power BI Desktop app and Power BI services.

Power BI Tutorial: Sentiment Analysis

Step 20

We can see the data flow we created named, news_data in the workspace News_demo.

Power BI Tutorial: Sentiment Analysis

Now, let us load the data in Query Table. 

Power BI Tutorial: Sentiment Analysis

Step 21

Now, let us map out our data into visualization.

Power BI Tutorial: Sentiment Analysis

Let us choose the Stack bar Chart for it.

Power BI Tutorial: Sentiment Analysis

Let us use the Topic Column as Axes and Sentiment as Legend and the count of Sentiment as Value which can be done by dragging and dropping the Sentiment into the Values field. 

Power BI Tutorial: Sentiment Analysis

This will provide us the Visualization. 

Step 22

We can clearly see, the representation of the data into charts through the visualization capabilities of Power BI. The Sentiment for Topic Obama can be viewed with a high number of neutral and few Positive.

Power BI Tutorial: Sentiment Analysis

Realizing, how swiftly and easily the power of AI can be employed with the tools provided in Power BI that deploys the possibilities of Azure Cognitive Services is astounding. From simple data preparation to manifesting artificial intelligence, all of it just being within the Power BI app demonstrates what a powerhouse of a tool it is, henceforth the name – POWER BI. Moreover, not all the cognitive services features are available directly in Power BI as of now. If required, one can do it through the REST API of Azure Cognitive Service but one would require the Azure Subscription for it. 

Conclusion

In this article, we learned about Power BI and used it in conjunction with the feature of the Azure Cognitive Services Text Analysis Model to figure out the sentiment of the News. We learned from a brief intro to these tools and dived into a real-world example through a hands-on step-by-step process. This is just a minuscule version of what is possible with Power BI and Azure Cognitive Services when worked together. The synergy these two powerful tools bring is majestic and the possibilities are endless when it comes in the hand of skillful Data Analysts and Data Scientists.