web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Sum( Gallery.AllItems,...
Power Apps
Unanswered

Sum( Gallery.AllItems, TextInput.Text ) not working as expected

(0) ShareShare
ReportReport
Posted on by 8

Hello,

 

I am trying to calculate the sum of all items within a gallery, based on each item's TextInput.Text value. I'm attempting this code to calculate the sum:

Sum( Gallery.AllItems, Value( TextInput.Text ) )

 

The above code is what I've researched as the best solution, but it doesn't work as expected. Instead of adding each item's TextInput.Text value, it takes the first item's TextInput.Text value and multiplies it by the number of items in the gallery.

 

Instead of: Sum( {34}, {33}, {33} ) = 100

It actually calculates: Sum( {34}, {33}, {33} ) = 102, or {34} * 3

 

1. I thought this could be a disambiguation issue, so I tried resolving it from that perspective. No resolution.

2. I thought the data type could be incorrect, but no resolution found.

3. I thought a property within the control might be wrong, no resolution found.

4. I un-nested the control out of a container, so that the TextInput control had the Gallery as its parent. No resolution.

 

I realize that I could use the OnChange property to Patch() the data source (which is a collection in my case), but I've found that using Patch() freezes the app for a split second while the code is executed, and selection of the control is reset, which disrupts tabbing through the controls, making for a unpleasant user experience.

 

Does anyone have a reasonable solution for this? Do I have to lower my expectations and use the OnChange property to Patch()?

Categories:
I have the same question (0)
  • EddieE Profile Picture
    4,641 Moderator on at

    @Paradise103 

    Your formula works on a simple gallery structure with a label outside of it for the Sum, ie

    EddieE_0-1701727634220.png

     

    You mention containers and un-nesting so my guess is that's where your issue/s lies. There's nothing wrong with your code.

     

     

  • Paradise103 Profile Picture
    8 on at

    The Sum( Gallery.AllItems, Value( TextInput.Text ) ) is located in a control outside of the gallery, not in a container. And the TextInput control I am trying to sum inside of the gallery was nested within a container - but I've tried un-nesting that TextInput, and it still didn't help with the evaluation.

  • EddieE Profile Picture
    4,641 Moderator on at

    @Paradise103 

    Can you share an image showing your app screen setup, I'm still not understanding why it's not working. I added a container, pasted the gallery inside that container, left the label for Summing outside the container and it still works for me

     

    EddieE_0-1701748086593.png

     

     

  • Paradise103 Profile Picture
    8 on at

    Paradise103_0-1701784462004.png

    Here's what I'm working with. The AllocationInput control is not nested, and resides in the Gallery. The selected control, where my code lives, is outside of the Gallery.

  • EddieE Profile Picture
    4,641 Moderator on at

    @Paradise103 
    From what I can see that's returning the correct value, ie

     

    0.3333 + 0.3333 + 0.3334 = 1.000, not allowing for any rounding taking place

     

     

  • Paradise103 Profile Picture
    8 on at

    @Ed , the screenshot clearly shows the result as 1.0002, which is 0.3334*3. 

  • Paradise103 Profile Picture
    8 on at

    I'm beginning to think this is either a bug or disambiguation issue. When I use a ForAll( Gallery, Patch() ) function to save all the gallery items using each item's control values (instead of the underlying collection values), the first item's contents are patched 3 times over (the number of items in the gallery). When I use the same function on the collection values, I don't have any issues.

  • EddieE Profile Picture
    4,641 Moderator on at

    @Paradise103 

    What's the formula for the label displaying the %'s values? Can you show these values in a separate label then do that SUM?

     

    Could you also show a relevant pic of your tree structure

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 483

#2
WarrenBelz Profile Picture

WarrenBelz 399 Most Valuable Professional

#3
11manish Profile Picture

11manish 327

Last 30 days Overall leaderboard