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 / How to do math inside ...
Power Apps
Answered

How to do math inside patch function

(0) ShareShare
ReportReport
Posted on by 81

Hi.

 

I'm trying to get this to work:

 

SubmitForm(Form1);; Patch( '[dbo].[Grupper]'; LookUp('[dbo].[Grupper]'; kar_id = varKarId); { antall: Value(DataCardValue7.Text) - Value(DataCardValue3.Text) });; NewForm(Form1)

 

, but it seems the math part 

 

Value(DataCardValue7.Text) - Value(DataCardValue3.Text

 

doesn't work inside the patch function. I've gotten it to work in a label, though.

 

Do I have to do the math in a hidden label and refer to that label inside the patch function or is an easier way possible?

Categories:
I have the same question (0)
  • Verified answer
    9kMan Profile Picture
    81 on at

    I figured it out. I had to submit the form AFTER the patch statement. Silly mistake. 

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @9kMan 

    First, you should move the Patch to the OnSuccess action of your EditForm.  As you have your formula now, if the initial submit fails, your Patch would still happen.  If you move this formula to the OnSuccess, then you will be assured that the initial submit was a success and then your patch can proceed.

     

    Also, it is not good to refer to the DataCard controls after you submit.  Instead you would want to refer to the submitted values.  This is found in the LastSubmit property of your form.  So, without knowing what your DataCardValue7 or DataCardValue3 are based on (i.e. the column name in your datasource), then your formula in your OnSuccess would be the following:

    Patch('[dbo].[Grupper]'; 
     LookUp('[dbo].[Grupper]'; kar_id = varKarId); 
     { 
     antall: Form1.LastSubmit.antall - Form1.LastSubmit.otherColumn
     }
    );; 
    
    NewForm(Form1)

     

    Also, if kar_id is something that is actually submitted in some way through your form, then you can replace the entire formula with the following:

    UpdateIf('[dbo].[Grupper]'; 
     kar_id = Form1.LastSubmit.karID; //or whatever it is called
     { 
     antall: Form1.LastSubmit.antall - Form1.LastSubmit.otherColumn
     }
    );; 
    
    NewForm(Form1)​

    This just saves the cost of doing a LookUp on the record and is a bit more faster.

     

    I hope this is helpful for you.

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @9kMan 

    Please read my response - with your current method of Patching first, you risk a record patch that might not be reflective of your scenario if there is a submit failure.

  • 9kMan Profile Picture
    81 on at

    Thanks! I didn't know about the LastSubmit function. Didn't think of using the OnSuccess action either. 

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!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 551

#2
WarrenBelz Profile Picture

WarrenBelz 430 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 298

Last 30 days Overall leaderboard