PowerApps Rating Control Total and Average Ratings Validations

Introduction

Rating is one of the most common features in social sites and for any of the interactive requirements by users. While I was developing ratings, I realized, there are lots of validation required in order to capture correct ratings.

Scenario

We will add a rating control and set display mode as per the requirement. We will also capture all the ratings and project average ratings.

Objective

The objective of this requirement is very demanding as rating the concept is important in many of the scenarios. It is useful in concepts like idea ratings or article ratings. To calculate and project we will create a SharePoint list as per the requirements.

Step 1. The list structure would look like below-

The list structure could be designed as per our needs. Here for a demo, I have created 3 different lists and shown the data with its list structure.

Article list structure.

 List structure

Article list content.

Article list

PostViewsOnArticle list structure.

PostViews

PostViewsOnArticle Content.

Content

The third list will save data from power apps, and the list structure looks like below.

View Rating

Step 2. Design screen and form as per requirement.

The below screenshot shows all the articles that are entered, on clicking on articles, we can see the details of the article and all the views that we got on that article. To show all articles, I have taken gallery control.

Design Screen

Below is the display form, which shows the variable View value. Variable View value shows gallery-selected item details.

Edit

Below form I would like to show all the views that people might have. When we click on each of the views, we can see the details and after seeing the details, we can rate it. To show all the views, we will again use Gallery control.

As we can see, I have deleted the title from the box label and provided a button so that I can show the title as text, and it remains clickable too.

Power Apps

On selecting the button, it should go to View description so the code looks like below.

View

Step 3. Save the Logged User in a Global variable

We keep logged-in user details in a global variable for performance improvement. Otherwise User(). The email could directly be used wherever required.

Global variable

Step 4. Add Rating list DataSource from SharePoint

Add Rating List from SharePoint as DataSource.

So that the patch function can use this data source to store the ratings.

SharePoint

Insert

Step 5. DisplayMode property of Rating Control.

DisplayMode property of rating control at Article description page and views gallery.

DisplayMode

Step 6. Default property of Rating Control.

Default property of Rating control.

Default property

Step 7. OnSelect property of Rating Control.

Below the OnSelect property, the function is optional in case it is needed. In my case, it is not required as the rating control is in view mode.

Property

Step 8. Create a new screen and a new form to show view details.

It is a representation of another method of rating control. What we saw in the above screen, little more in detail we will see in this screen. We will see validations on rating control in this scenario.

New Screen

Step 9. Add Rating Control to record ratings. Default Property of Rating Control.

As shown steps above to add rating control and set the default value to 0 are followed. Unlike above here, the display mode will depend upon the validations.

Same above feature we will be on a form where the user can view all the details of the item and then choose to rate, so we will include a rating control on the below form which will show average ratings and total ratings and patch the ratings, your own ratings given will be shown.

Rating App

Step 10. Here Display mode will not be viewed directly. It will work depending on the validations.

Below is another example with validation to set Display mode.

Display mode

Step 11. OnSelect of Rating Control

Since I have handled the displaymode, It is not required to do validation on OnSelect so I am patching directly to the list.

Rating Control

Step 12. Average Ratings

Change the form mode to new or edit as needed. This step is just for a thought in case the form is not loaded correctly.

Average Ratings

Step 13. Total Ratings

Total Ratings

Conclusion

In the above example we saw how could we use rating control, how the data be saved in the SharePoint list, how could average rating be taken out, and how to show a total number of stars rated.


Similar Articles