Skip to main content

Notifications

Community site session details

Community site session details

Session Id : aMwk55Ep6MjdKSvK6UAhIi
Power Apps - Building Power Apps
Answered

Sum function in PowerApps recalculates based on the currently visible items in the gallery. When you change pages, the visible items change, which resets the sum.

Like (0) ShareShare
ReportReport
Posted on 25 Jun 2024 04:57:27 by

I HAVE A GALLERY WITH ITEMS PROPERTY WITH THE FOLLOWING

 

 
FirstN(
LastN(
Distinct(
Filter(
'Impact ',
'Risk _Category '.Risk_name = VarTop.Risk_name
),
Question
),
CountRows(
Distinct(
Filter(
'Impact ,
'Risk _Category '.Risk_name = VarTop.Risk_name
),
Question
)
) - (varCurrentPage - 1) * 4
),
4
)

 

I have a next button which is outside the gallery, when user clicks on it, the next four items will display

 

If(
varCurrentPage < RoundUp(
CountRows(
Distinct(
Filter('Impact ,'Top IT .Risk_name = VarTopItForBottomUp.Risk_name
),
Question
)
) / 4,
0
),
Set(varCurrentPage, varCurrentPage + 1)
)

 

I have a previous button which is outside the gallery, when user clicks on it, the previous four items will display

 

 

If(
varCurrentPage > 1,
Set(
varCurrentPage,
varCurrentPage - 1
)
)


I have a label which is inside the gallery the gallery which shows the value of the impact

 

I have another label which is outside the gallery which shows the sum of values inside the gallery Label

 

Sum(
ForAll(
Gallery4.AllItems,
Value(Label5.Text)
),
Value
)


The problem Iam facing is when clicks on the next button the count of the sum which is done for the first 4 items is gone
and starting from the default as Zero

 

the sum resetting when navigating through pages in My gallery. the fact that the Sum function in PowerApps recalculates based on the currently visible items in the gallery. When you change pages, the visible items change, which resets the sum.

 

Could anyone please help me to fix the issue 

 

  • WarrenBelz Profile Picture
    146,821 Most Valuable Professional on 27 Jun 2024 at 08:20:30
    Re: Sum function in PowerApps recalculates based on the currently visible items in the gallery. When you change pages, the visible items change, which resets the sum.

    @Danny_Dicaprio ,

    You need to either use the Label or a field in the Items. If not, you would need a separate filter to what is displayed in the Gallery and do a sum on that.

  • Danny_Dicaprio Profile Picture
    on 26 Jun 2024 at 04:28:23
    Re: Sum function in PowerApps recalculates based on the currently visible items in the gallery. When you change pages, the visible items change, which resets the sum.

    HI @WarrenBelz 

     

    Thanks for the response

     

    so if u could see my screenshot for all the responses choosed by the user I have value corresponding to that column in the dataverse table 

     

    Danny_Dicaprio_0-1719376032120.png

     

     

    Is there is any way we could do the calculation without using the label inside the gallery 

  • WarrenBelz Profile Picture
    146,821 Most Valuable Professional on 25 Jun 2024 at 11:40:26
    Re: Sum function in PowerApps recalculates based on the currently visible items in the gallery. When you change pages, the visible items change, which resets the sum.

    Hi @Danny_Dicaprio ,

    That is not going to work with what you are doing as Sum(Gallery . . .) will only add what is displayed by the Gallery Items. The problem also is that there is no control over how many times or in what order the user clicks the two buttons, so doing some sort of progressive Variable is problematic.

  • Danny_Dicaprio Profile Picture
    on 25 Jun 2024 at 09:54:01
    Re: Sum function in PowerApps recalculates based on the currently visible items in the gallery. When you change pages, the visible items change, which resets the sum.

    Hi @WarrenBelz 

     

    Thanks for the response

     

    when I click on the next button the previous sum is not getting calculated along with the new sum

     

    Iam looking for the final sum in the label from all the items 

    Sum(
     Gallery4.AllItems,
     Value(Label5.Text)
    )

    in the label outside the gallery it is showing the count of the last 4 items in the gallery , Not the previous one 

     

     

  • WarrenBelz Profile Picture
    146,821 Most Valuable Professional on 25 Jun 2024 at 06:54:01
    Re: Sum function in PowerApps recalculates based on the currently visible items in the gallery. When you change pages, the visible items change, which resets the sum.

    @Danny_Dicaprio ,

    The Sum seems to be correct based on the figures at the right of the items - what is not working ?

  • Danny_Dicaprio Profile Picture
    on 25 Jun 2024 at 05:59:47
    Re: Sum function in PowerApps recalculates based on the currently visible items in the gallery. When you change pages, the visible items change, which resets the sum.

    Hi @WarrenBelz 

     

    Thanks for the response but still Iam facing the same issue 

     

     

    I have updated the items gallery and the label

     

    Spoiler (Highlight to read)

     

     

    when I clicks on the Next button the above label which shows the count 11 is getting back to  default 

    Spoiler (Highlight to read)

     

     

     

  • Verified answer
    WarrenBelz Profile Picture
    146,821 Most Valuable Professional on 25 Jun 2024 at 05:42:20
    Re: Sum function in PowerApps recalculates based on the currently visible items in the gallery. When you change pages, the visible items change, which resets the sum.

    Hi @Danny_Dicaprio ,

    Just did a test here using a similar structure test list - apart from cutting down the Items to

    With(
     {
     _Data:
     Distinct(
     Filter(
     'Impact & Assessment Evaluations',
     'Top IT Risk _Category '.Risk_name = VarTopItForBottomUp.Risk_name
     ),
     Question
     )
     },
     FirstN(
     LastN(
     _Data,
     CountRows(_Data) - (varCurrentPage - 1) * 4
     ),
     4
     )
    )

    and the Label to

    Sum(
     Gallery4.AllItems,
     Value(Label5.Text)
    )

    with the other to the same, it worked perfectly as below.

    pagination.gif

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

     

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Building Power Apps

#1
MS.Ragavendar Profile Picture

MS.Ragavendar 32

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 19 Super User 2025 Season 1

#3
WarrenBelz Profile Picture

WarrenBelz 18 Most Valuable Professional

Overall leaderboard