In this Power Apps tutorial, we will discuss how to calculate sum of gallery items in Power Apps. To calculate the sum of the Power Apps gallery items, we are going to use the PowerApps Sum() function.
Recently, I was working in a canvas app in Power Apps, where we were displaying items from a SharePoint list using a gallery control. Here we have the requirement to calculate the total of a column in the gallery control.
Like, we have a Total Price column, and we wanted to display the total of that column.
To meet this requirement, the following steps are:
Calculate the sum gallery items in Power Apps
Let us understand, how to calculate the sum of the gallery items within the Power Apps. That is, we will use Power Apps to calculate the sum of the gallery items based on the quantity and price.
The total price of each product will be calculated in the gallery based on the respective order quantity. After that, it will calculate the sum of the gallery items’ total prices.
Here, we have a SharePoint list named Orders list having some different types of columns such as:
- Title: Default
- Order Date: Date and time
- Order Qty: Number
- Manufacturer: Choices
- Price: Currency
To fulfill the requirement, now we will create a vertical gallery within the Power Apps screen and connect that vertical gallery to the SharePoint data source. For this, the following steps are:
- On the Power Apps Canvas app, go to Add Data > Connect the SharePoint list.
- On the screen, click on the Insert > Vertical gallery.
- Connect the gallery with the SharePoint list i.e., Orders list.
- Now the gallery will display the columns that were retrieved from the SharePoint list.
- Now, we’ll add a new column to the data source that will calculate the total price of each product based on the quantity of the order. For this, insert the below expression on the gallery’s Items property.
Items = AddColumns('Orders List', "Total Product Price",'Order Qty'* Price)
- ‘Orders List‘ is the name of the SharePoint list.
- “Total Product Price” is the name of the new column to store the calculated value.
- Order Qty and Price are the names of the columns of the SharePoint list.
- Let’s display that evaluation in the gallery. For that, add a label control into the gallery and insert the below expression in the label’s Text to display the new column’s values.
Text = ThisItem.'Total Product Price'
- Finally, we will calculate the sum of the total products’ prices and display that total value within the gallery.
- For this, add a label control and insert the below expression on the label’s Text property.
Text = "Total Price = " & Sum(Gallery1.AllItems,'Total Product Price')
Where Gallery1 is the name of the PowerApps vertical gallery. Once the formula is applied, the sum value will display within the screen’s label.
This is how to calculate the sum of gallery items within Power Apps.
From this Power Apps Tutorial, we learned how to calculate the sum of Power Apps gallery items.
You may also like the following Power Apps tutorials:
- How to set default value in Power Apps data card?
- How to copy Power Apps Data Card value to another
- How to change Power Apps DataCard to dropdown
- Update DataCard Value in Power Apps
- How to get month name from date in Power Apps
After working for more than 15 years in Microsoft technologies like SharePoint, Office 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (9 times). I have also worked in companies like HP, TCS, KPIT, etc.