Power Apps: Comment Sentiment Analyse App with Dataverse AI Functions

Lütfi Dereli
5 min readMay 27, 2024

--

AI-based development and built-in AI features are increasing day by day on the Microsoft Power Platform. It’s quite helpful to create new AI features using native functions within the application, as this makes development easier and helps prevent overall complexity.

For example, when developing an application that uses a sentiment analysis model, you need to use AI Prompts. (You can find an example created using AI Prompts in my other article). This means you need to do some preparation before creating a canvas app.

Now, you can easily handle to create some AI based features via Dataverse AI Functions. (You can find more information about Dataverse AI Functions via official Microsoft documentation)

What will we do?

First of first we will quickly look at those functions and create sample Comment Sentiment Analyse App

What is Dataverse AI Functions?

Dataverse provides a variety of ready-to-use AI functions that are preconfigured and don’t require any data collection, building, or training. You can use these prebuilt AI functions in your app and workflows to improve functionality and streamline processes. The AI functions work with canvas apps, AI Builder, and low-code plugins so can easily integrate them into your solutions.

Briefly says you can directly create your own AI features within PowerFX formula bar, but how, let’s look at closer it then

What are those AI functions?

In a nutshell:

  • AIExtract
  • AIReply
  • AISentiment
  • AISummarize
  • AITranslate

You can find more detailed information for each member of the function’s description at official documentation. Let’s we getting our hands dirty!

Create Data Sources

Before adding controls to your canvas, you need to know that to use these functions, you must import the Environment Dataverse table into your application. The Dataverse Environment table is a crucial component of Microsoft Dataverse, a cloud-based storage solution for securely managing business application data. It helps organize and manage data and resources within Microsoft Power Platform and Dynamics 365.

IMPORTANT: You should have enough AI Builder capacity to use the functions otherwise you can’t

I used two types different kind of data source to get the data to application. One of them Dataverse table another one is Sharepoint list.

Sharepoint List

You can easily create or import kind of dataset as well

Dataverse Table

I have created a sample Dataverse table containing short comments about products using the AI Dataverse table creator (AI Co-Pilot). Be sure that the related data between the two tables have the same unique ID. To ensure this, I created a basic autonumber ID column in this table using AI Co-Pilot.

Create Canvas App

After creating a canvas application, click on New Screen and add Split Screen

Split Screen

If you prefer you can add header and footer as well.

After you completed adding a screen to your canvas, you need to add three data sources:

Add three datasources

I prefered using one of the datasource is Sharepoint, another one is Dataverse but, additionally you need to add Environment data source. This datasources host multiple information about your enviroment, AI Builder capacity, credit information are some of them, so you are going to use this datasource to start in-built AI features

Let’s add an gallery to left side of the screen, and named it as gal_devices; right side will a screen that show the customer results, ratings etc. that will adding later on.

gal_devices

As an example, just add text label to gal_devices gallery.

  • Click on first record of the gallery and add this PowerFX formulate to OnSelect property
Set(
Result,
Environment.AISentiment(
{
Text: LookUp(
'Customer Comments',
ThisItem.DeviceID = Value(DeviceID)
).Comment
}
).AnalyzedSentiment
);

As you can see, we set a global variable which name is Result and add our logic formula. The most important part of the formula is Environment.AISentiment(your formula).AnalyzedSentiment.

Set( Result, Environment.AISummarize( {Text:Subject} ).SummarizedText )

Text - Required. The text to summarize.
For canvas apps, the return value is in the SummarizedText column.

Above formula is an example format of the AI Summarize Dataverse function that made of Text and .SummarizedText.

The second part of the code creates a new collection to gather comments and rating information when the user clicks on a related record in the gallery. It compares the ID values between the Devices Dataverse table and the SharePoint list to check for a match. If the IDs match correctly, the result will be displayed in the collection.

ClearCollect(
col_comments,
{
Rate: LookUp(
'Customer Comments',
ThisItem.DeviceID = Value(DeviceID)
).Rating,

Comment: LookUp(
AddColumns(
'Customer Comments',
Sentiment,
Result
),
ThisItem.DeviceID = Value(DeviceID),
Comment
)
}
);

Rate: It collects data matched rating records and save it to Rate column on the collection

Comment: It collects data matched comments records and save it to Comment column on the collection

Last view of the gal_devices gallery’s onSelect property

Now, time to shaped second gallery of the screen which will show related information which regarding to clicked; what comments and rating of the selected item.

gal_comment gallery

Add a new gallery control and set Items property as col_comments. Add Comment, Sentiment and Rate text inputs and their value. In total, you need to add 4text inputs control and one rating control which you can find in modern controls to this gallery.

Lastly, just add ThisItem.Comment, Result, ThisItem.Rating to related controllers. When you click an item of the devices, you can find the user comment and sentiment analysis itself.

Conclude,

If you want, you can add some UI to get more attractive like colors, font weight etc.

Final view of the Comment Sentiment Analyse App

Comment Sentiment Analyse App

--

--

Lütfi Dereli
Lütfi Dereli

Written by Lütfi Dereli

Power Platform Developer | Digital Citizen | Data Enthusiast | TechInLove —

No responses yet