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 / Adding/Subtracting pow...
Power Apps
Answered

Adding/Subtracting power apps columns

(0) ShareShare
ReportReport
Posted on by 350

The following attempts to subtract or add inventory. I have an ON_HAND function that subtracts from one warehouse and adds the
inventory to the second warehouse.   Instead it does something strange.  The function below adds the number 1 to the on hand inventory.  Say I have 100 forms on hand. But I want to transfer 200 below the error pops up informing the user  that it cannot transfer due to insufficient available on hond.  Instead it adds a number 1, yes number 1 to the available on hand. 

Below is the function I'm using. 

 

Any help is much appreciated.  

 

 

UpdateContext({isVisible:false});
With(
{
wLookUp: LookUp(
OPTrack_FormsInventoryEnhancedTables,
FORM_NO = ddl_Form_No.Selected.Value && WAREHOUSE = ddl_From_Warehouse.Selected.Value
)
},
Patch(
OPTrack_FormsInventoryEnhancedTables,
wLookUp,
{
ON_HAND: If(wLookUp.'ON_HAND' < Value(txtQuantity_6.Text), UpdateContext({isVisible:true}), wLookUp.'ON_HAND' - Value(txtQuantity_6.Text))
}
)
);
With(
{
wLookUp: LookUp(
OPTrack_FormsInventoryEnhancedTables,
FORM_NO = ddl_Form_No.Selected.Value && WAREHOUSE = ddl_To_Warehouse.Selected.Value
)
},
Patch(
OPTrack_FormsInventoryEnhancedTables,
wLookUp,
{
ON_HAND: If(wLookUp.'ON_HAND' < Value(txtQuantity_6.Text), UpdateContext({isVisible:true}), wLookUp.'ON_HAND' + Value(txtQuantity_6.Text))
}
)
);

Categories:
I have the same question (0)
  • Verified answer
    WarrenBelz Profile Picture
    156,434 Most Valuable Professional on at

    Hi @rroque ,

    You seem to have duplicated your code in the post, but you need to get the on hand logic outside the Patch

    UpdateContext({isVisible:false});
    With(
     {
     wLookUp: 
     LookUp(
     OPTrack_FormsInventoryEnhancedTables,
     FORM_NO = ddl_Form_No.Selected.Value && 
     WAREHOUSE = ddl_From_Warehouse.Selected.Value
     )
     },
     If(
     wLookUp.'ON_HAND' < Value(txtQuantity_6.Text),
     UpdateContext({isVisible:true}),
     Patch(
     OPTrack_FormsInventoryEnhancedTables,
     wLookUp,
     {ON_HAND: wLookUp.'ON_HAND' - Value(txtQuantity_6.Text)}
     )
     )
    );

     

    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

  • rroque Profile Picture
    350 on at

    Thank you so much. Much appreciated/

  • rroque Profile Picture
    350 on at

    Hi Warren I'm getting some weird behavior when adding inventory. Would you take a look at this if you can. 

    You'll notice I have subtrac and addition for both from and to warehouses.  Whats happening the second with section is just pulling in the numbers from the 1st with function.  

     

    UpdateContext({isVisible:false}); UpdateContext({isSaved:false});
    With(
    {
    wLookUp:
    LookUp(
    OPTrack_FormsInventoryEnhancedTables,
    FORM_NO = ddl_Form_No.Selected.Value && WAREHOUSE = ddl_From_Warehouse.Selected.Value
    )
    },
    If(
    wLookUp.ON_HAND >= Value(txtQuantity_6.Text),
    Patch(
    OPTrack_FormsInventoryEnhancedTables,
    wLookUp,
    {ON_HAND: wLookUp.'ON_HAND' - Value(txtQuantity_6.Text)}
    ), UpdateContext({isVisible:true})
    )
    );
    With(
    {
    wSearch: LookUp(OPTrack_FormsInventoryEnhancedTables,
    FORM_NO = ddl_Form_No.Selected.Value && WAREHOUSE = ddl_To_Warehouse.Selected.Value
    )
    },
    Patch(
    OPTrack_FormsInventoryEnhancedTables,
    wSearch,
    {ON_HAND: wSearch.ON_HAND + Value(txtQuantity_6.Text)}
    )
    )

     

  • rroque Profile Picture
    350 on at

    The problem I'm having is this. There are to two lookups one for my source warehouse and the other for my receiving warehouse,

    I have no way or understanding how to deal with the first piece of code as a result the code always adds to the receiving warehouse. 

     

    Any help is much appreciated.  

    // recieving warehouse

    UpdateContext({isVisible:false});
    With(
    {
    wLookUp:
    LookUp(
    OPTrack_FormsInventoryEnhancedTables,
    FORM_NO = ddl_Form_No.Selected.Value && WAREHOUSE = ddl_To_Warehouse.Selected.Value
    )
    },
    Patch(
    OPTrack_FormsInventoryEnhancedTables,
    wLookUp,
    {
    ON_HAND: wLookUp.ON_HAND + Value(txtQuantity_6.Text)
    }
    )
    );

    // source warehouse

    With(
    {
    wLookUp:
    LookUp(
    OPTrack_FormsInventoryEnhancedTables,
    FORM_NO = ddl_Form_No.Selected.Value && WAREHOUSE = ddl_From_Warehouse.Selected.Value
    )
    },
    If(
    wLookUp.ON_HAND < Value(txtQuantity_6.Text),
    UpdateContext({isVisible:true}),
    Patch(
    OPTrack_FormsInventoryEnhancedTables,
    wLookUp,
    {ON_HAND: wLookUp.ON_HAND - Value(txtQuantity_6.Text)}
    )
    )
    )

  • rroque Profile Picture
    350 on at

    Thanks so much Warren with your help I found the answer.

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 July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 329 Most Valuable Professional

#2
11manish Profile Picture

11manish 209 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 179

Last 30 days Overall leaderboard