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 / Patch and subtract val...
Power Apps
Answered

Patch and subtract value when a dropdown value is selected

(1) ShareShare
ReportReport
Posted on by 25

I have a SharePoint list, cash counts and I have a dropdown for a branch name which have a column name in the list. Also, I have a column for the required cash counts. In the app, I have a form which have a dropdown for the branch name and a text input for the required cash count. The default value for the required cash count is 2.

Now, I want to subtract the cash count to 1 if the user submit a record based on the selected branch name on the drop down.
Once the user already submitted a record under the same branch name, the required cash count will be 1 already and when they want to submit another record for the same branch, the required cash count text input will display 1.

Once the text input for the required cash count reaches 0, the user cannot submit a record for their selected branch name.

any idea how to do this? Thanks.

Categories:
I have the same question (0)
  • Verified answer
    poweractivate Profile Picture
    11,078 Most Valuable Professional on at

    Fetch the Current Cash Count for the Selected Branch

    • When a user selects a branch from the dropdown, you should retrieve the current required cash count from the SharePoint list using the LookUp function.
    • Set a context variable to hold the current required cash count.

     

    • In the OnChange property of your Dropdown Control:
    UpdateContext({varBranchCashCount: LookUp(SharePointListName, Branch = Dropdown1.Selected.Value)});
    UpdateContext({varRequiredCashCount: varBranchCashCount.RequiredCashCount});
    

    Display the Required Cash Count in the Text Input

     

    In the Text Input  - in the Default property:

    varRequiredCashCount
    

     In a Submit (Button Control), in the OnSelect property

    If(
     varRequiredCashCount > 0,
     Patch(
     SharePointListName,
     {ID: varBranchCashCount.ID, RequiredCashCount: varRequiredCashCount - 1}
     );
     UpdateContext({varRequiredCashCount: varRequiredCashCount - 1})
     // Optionally, provide feedback if submission is successful such as using Notify function
    )

    If you want to show info if it works or not use Notify function like below:

    If(
     varRequiredCashCount > 0,
     (
     Patch(
     SharePointListName,
     {ID: varBranchCashCount.ID, RequiredCashCount: varRequiredCashCount - 1}
     );
     UpdateContext({varRequiredCashCount: varRequiredCashCount - 1});
     Notify("Submission successful. Required cash count has been updated.", NotificationType.Success)
     ),
     Notify("Submission failed. Required cash count has reached 0 for the selected branch.", NotificationType.Error)
    )
    

    @jasminemeneses See if it helps.

  • jasminemeneses Profile Picture
    25 on at

    Under the OnSelect property in the Submit button, I encounter an error on the bold text especially on the semicolon on the end of the patch function. I added also some validation on the first part of the if statement.

    If(
    IsBlank(ComboBox1) Or IsBlank(DataCardValue18) Or IsBlank(DataCardValue23) Or IsBlank(DataCardValue24),
    Notify(
    "Must fill all the requirements.",
    NotificationType.Error
    ),
    If(
    Value(varRequiredCashCount) > 0,
    (
    Patch(
    'RBG Cash Count',
    {ID: varBranchCashCount.ID, 'Required Cash Count': varRequiredCashCount - 1}
    );
    UpdateContext({varRequiredCashCount: varRequiredCashCount - 1}),
    SubmitForm(Form1);
    ResetForm(Form1);
    Navigate(
    HomeScreen,
    ScreenTransition.Fade
    );
    Notify("Submission successful. Required cash count has been updated.", NotificationType.Success);
    ),
    Notify("Submission failed. Required cash count has reached 0 for the selected branch.", NotificationType.Error)
    );

  • poweractivate Profile Picture
    11,078 Most Valuable Professional on at

    @jasminemeneses 

    Or is a function in Power Apps and it's not a valid operator that can be used like the way you are doing here.

    You have to use || instead if you use it that way.

    If you want to use the word Or, it's like this instead:

    If(
     Or(
     IsBlank(ComboBox1), 
     IsBlank(DataCardValue18), 
     IsBlank(DataCardValue23), 
     IsBlank(DataCardValue24)
     ),
     Notify("Must fill all the requirements.", NotificationType.Error),
     If(
     Value(varRequiredCashCount) > 0,
     (
     Patch(
     'RBG Cash Count',
     {ID: varBranchCashCount.ID, 'Required Cash Count': varRequiredCashCount - 1}
     );
     UpdateContext({varRequiredCashCount: varRequiredCashCount - 1});
     SubmitForm(Form1);
     ResetForm(Form1);
     Navigate(HomeScreen, ScreenTransition.Fade);
     Notify("Submission successful. Required cash count has been updated.", NotificationType.Success)
     ),
     Notify("Submission failed. Required cash count has reached 0 for the selected branch.", NotificationType.Error)
     )
    )
    


    or to use Or the way you were doing initially you must use || instead like this:

    If(
     IsBlank(ComboBox1) || 
     IsBlank(DataCardValue18) || 
     IsBlank(DataCardValue23) || 
     IsBlank(DataCardValue24),
     Notify("Must fill all the requirements.", NotificationType.Error),
     If(
     Value(varRequiredCashCount) > 0,
     (
     Patch(
     'RBG Cash Count',
     {ID: varBranchCashCount.ID, 'Required Cash Count': varRequiredCashCount - 1}
     );
     UpdateContext({varRequiredCashCount: varRequiredCashCount - 1});
     SubmitForm(Form1);
     ResetForm(Form1);
     Navigate(HomeScreen, ScreenTransition.Fade);
     Notify("Submission successful. Required cash count has been updated.", NotificationType.Success)
     ),
     Notify("Submission failed. Required cash count has reached 0 for the selected branch.", NotificationType.Error)
     )
    )
    


    See if it helps @jasminemeneses 

  • jasminemeneses Profile Picture
    25 on at

    I encountered an error in the semicolon (;) after the patch function

    Screenshot (157).png

     

    When I try to change it to a colon(,) the whole code is a error

    Screenshot (158).png

  • Verified answer
    poweractivate Profile Picture
    11,078 Most Valuable Professional on at

    @jasminemeneses Semicolon is the corect one ;

    It's bizarre it should be fine, so try it without the grouping parentheses?

    If(
     IsBlank(ComboBox1) || 
     IsBlank(DataCardValue18) || 
     IsBlank(DataCardValue23) || 
     IsBlank(DataCardValue24),
     Notify("Must fill all the requirements.", NotificationType.Error),
     If(
     Value(varRequiredCashCount) > 0,
     Patch(
     'RBG Cash Count',
     {ID: varBranchCashCount.ID, 'Required Cash Count': varRequiredCashCount - 1}
     );
     UpdateContext({varRequiredCashCount: varRequiredCashCount - 1});
     SubmitForm(Form1);
     ResetForm(Form1);
     Navigate(HomeScreen, ScreenTransition.Fade);
     Notify("Submission successful. Required cash count has been updated.", NotificationType.Success),
     Notify("Submission failed. Required cash count has reached 0 for the selected branch.", NotificationType.Error)
     )
    )
    

    I assume 'RGB Cash Count' is your SP List, is that correct?

    If still error, mouse over the semicolon and tell me what the error is shown there.

  • jasminemeneses Profile Picture
    25 on at

    Thank you @poweractivate!

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 Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 326 Most Valuable Professional

#2
11manish Profile Picture

11manish 168

#3
sannavajjala87 Profile Picture

sannavajjala87 75 Super User 2026 Season 1

Last 30 days Overall leaderboard