How to Calculate Gallery Items in Power Apps?

In this Power Apps tutorial, I will show you how to calculate gallery items in Power Apps with various examples.

How to Calculate Gallery Items in Power Apps

To get the sum value from a gallery control, we can use the Sum function, like:

Sum(GalleryControlName.AllItems, 'ColumnName')

Let’s check how to get the sum of values from a gallery control.

Example 1: [Power Apps calculate the sum of gallery items]

I have a SharePoint list [ACGH Project Details] that has various columns like:

Column NameData type
Task NameTitle
Duration in daysNumber
StatusChoice [“Completed,” “In-progress,” “On-hold,” “Not-Started”]
Calculate sum of gallery items in Power Apps

The Power Apps gallery is connected to the above SharePoint list. The gallery contains a text label that displays the ‘Duration in days‘ for each task.

Next, I will add the total days from all the tasks and display the overall project duration, as shown below:

Power Apps Sum Values in a Gallery

Follow the below steps to achieve it:

  • Insert a Gallery control and set its DataSource property to:
Sort(
    'ACGH Project Details',
    Title,
    SortOrder.Ascending
)

Where,

  1. ACGH Project Tracker = SharePoint list name
  2. Title = SharePoint list title column
How to calculate sum of gallery items in Power Apps
  • To calculate sum values from gallery control, Insert a Text label and set its Text property to:
Sum(
    gal_ProjectDetails.AllItems,
    'Duration in days'
) & " Days"

Where,

  1. gal_ProjectDetails = Gallery control name
  2. Duration in days = SharePoint list number column
Sum value in Power Apps gallery
  • The text label will display the overall project duration days by calculating sum values from the ‘Duration in days’ gallery column.
Sum a gallery column Power Apps

This is how we can get the sum of values from a gallery control.

Example 2: Sum a gallery column that contains Lookup values

I have two SharePoint lists:

  1. ACGH Product Details
  2. ACGH Sales Tracking

The SharePoint list 1 [ACGH Product Details] has two columns:

Column NameData type
ProductTitle
Product PriceCurrency
Power Apps calculate sum of gallery items

The other SharePoint list 2 [ACGH Sales Tracking] has various columns like:

Column NameData type
SalesIDTitle
CustomerSingle line of text
ProductLookUp [Above SharePoint list, title column]
Power Apps sum a gallery column that contains Lookup values

The Power Apps gallery control is connected to the SharePoint list 2 [ACGH Sales Tracking.] Each customer has purchased multiple products, each with a different price.

Therefore, in the gallery control, I need to display the total price of products bought by each customer.

How to sum a gallery column in Power Apps

Follow the below steps to achieve it:

  • In the Power Apps gallery, insert a Text label control and set its Text property to:
Text(
    Sum(
        ForAll(
            ThisItem.Product.Value,
            LookUp(
                'ACGH Product Details',
                Title = Value,
                'Product Price'
            )
        ),
        Value
    ),
    "[$-en-US]$#,###.00"
)

Where,

  1. Product = SharePoint list2 lookup column name
  2. ACGH Product Details = SharePoint list1 name
  3. Title = SharePoint list 1 title column
  4. Product Price = SharePoint list1 currency column name
Sum a Power Apps gallery column that contains Lookup values
  • Now, we can see the sum of product prices bought by each customer in a gallery control.
Sum a Gallery Column in Power Apps

This is how we calculate the sum values in a Power Apps gallery control.

Also, you may like:

Conclusion

I hope this Power Apps tutorial taught you to calculate the sum of gallery items in Power Apps.

Moreover, you have learned how to sum a gallery column that contains Lookup values.