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 function on change...
Power Apps
Answered

Sum function on change of a value

(1) ShareShare
ReportReport
Posted on by 27

I have a SharePoint list with two numerical values. I customize the forms with PowerApps and I add a custom card to display the sum of the two values. When I edit a record, the form will load and sum the two values. How do I get the sum value to update when the user types in a new value in either of the two fields? 

 

I tried setting a variable in the OnChange entry for each field, and then displaying the variable as the Default entry on the total field. Typing in a new value now triggers the total to display the saved value, so not the one the person just typed in. 

Is there another on event I should be using? 

Categories:
I have the same question (0)
  • Verified answer
    turnerj3 Profile Picture
    2,039 on at

    What happens if you use the textbox value in the sum formula instead of a variable on change?

  • DB1 Profile Picture
    27 on at

    I'm not quite sure how to do that, if I set the text to be 

    "Total: " & Sum(ThisItem.'Basic Research 2022',ThisItem.'Basic Research 2023')

    then it sums the two values when editing an existing record, and does not update with changes until the form is saved and re-edited. 

  • DB1 Profile Picture
    27 on at

    If I just insert text input boxes and sum those, it works fine. The total updates with every change of either value with no configuration on my part. So getting that to work with the SharePoint list fields, or just setting the SharePoint fields to be the text input values is the goal now. 

  • HenWang Profile Picture
    Microsoft Employee on at

    Hi  @DB1 ,

     

    Do you mean that you want this total value to show up in your sharepoint list?

     

    If yes, you just need to create a new column with type: Calculated

    HenWang_0-1681283667294.png

     

    Since you are using power apps customized form, you can just hide this calculated column in your form and add a label to show the text you want in this customized form.

     

    Best Regards,

    Hen Wang

  • mattrogers Profile Picture
    3 on at

    I'm working on a project right now where I have a SharePoint list as a data source.  In my scenario, I have a "note" that gets added each time the record is updated.  I tried using the append feature, and I actually got close using a gallery, etc.. But then I landed on this solution that I think might help you:

    I have a label that displays the notes, but you can use a textbox, htmltext, etc. 

    On the Edit screen for the record, I added a button that opens a modal (it's just a group of rectangles and another textbox that appears on the highest layer, with a cancel and an ok button that makes everything trigger when it's clicked). 

    First, in App.OnStart, I set a variable to blank, like so:
    App.OnStart = Set(varNotes, "");

     

    Next, when the user selects a record, that is the only time we need them to add a note, so when the Edit screen becomes visible, I capture the value of that field and store it in the variable:
    Screen_Edit.OnVisible = Set(varNotes, If(IsBlankOrError(Gallery2.Selected.StatusUpdateNotes, "", Gallery2.Selected.StatusUpdateNotes));

     

    On the edit screen, I have a label that displays the variable varNotes.
    lblNotes.Text = varNotes;


    Now, on the edit page, with the modal open, looking at the "OK" button code, I set that variable to whatever is desired to see, and set the variable to that value:
    Patch(MySPlistDataSource, LookUp(MySPlistDataSource, Title = txtUserNotesInput.Text),{StatusUpdateNotes: varNotes});
    NotesOkButton.OnSelect = Set(varNotes, txtNotes.Text);
    // And here I have various code elements that hide the modal group

    When the last bit of code runs, it updates the label, and I don't have to refresh or do anything fancy, it just updates and the record itself also has the updated information.
    You might also consider using UpdateIf() or UpdateContext(), but this works for me.

    Please note that you'll need to update the Patch() function accordingly for your scenario if you choose to use it, but hopefully this gets you started.

    edit: after re-reading the OP's post, I think they may benefit from using a timer, set it to half a second (500), and then on Timer.OnEnd just set the variable to sum the input boxes.  So every half a second, it'll update.  You can adjust this down to 1/10th of a second but anything under 100 won't make a difference from what I can tell.

  • DB1 Profile Picture
    27 on at

    I also used a modal in my project, thanks for sharing that part of yours. 

    I ended up setting the text boxes to variables, and then the variables to the sharepoint list fields. Worked like a charm. 

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
wolenberg_ Profile Picture

wolenberg_ 119 Super User 2026 Season 1

#2
WarrenBelz Profile Picture

WarrenBelz 107 Most Valuable Professional

#3
Haque Profile Picture

Haque 103

Last 30 days Overall leaderboard