cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted

Patch to update or create item with addition (+)

Dear @PowerAddict@mdevaney and others, 

 

I am developing a patch function to update details to my Inventory List. Following is the formula I am using. But it has an error, 

 

If(ComboBox2_3.Selected.Value in Inventory.ModelNumber,Patch(Inventory,LookUp(Inventory,ModelNumber=ComboBox2_3.Selected.Value),{ModelNumber:ComboBox2_3.Selected.Value,Brand:Label27.Text,PurchaseQty:Inventory.PurchaseQty+qtyinput_1.Text}),Patch(Inventory,Defaults(Inventory),{ModelNumber:ComboBox2_3.Selected.Value,Brand:Label27.Text,PurchaseQty:qtyinput_1.Text}))

 

Annotation 2019-12-03 090608.jpg

 

What I want is If the modelnumber already exists in the list then add the qty from qtyinput_1 to Inventory.PurchaseQty

 

How can I resolve this?

 

Osmand

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Patch to update or create item with addition (+)

Hi @OsmandFernando ,

 

Please try with below formula instead:

If(ComboBox2_3.Selected.Value in Inventory.ModelNumber,Patch(Inventory,LookUp(Inventory,ModelNumber=First(ComboBox2_3.SelectedItems).Value),{ModelNumber:ComboBox2_3.Selected.Value,Brand:Label27.Text,PurchaseQty:LookUp(Inventory,ModelNumber=First(ComboBox2_3.SelectedItems).Value).PurchaseQty+qtyinput_1.Text}),Patch(Inventory,Defaults(Inventory),{ModelNumber:First(ComboBox2_3.SelectedItems).Value,Brand:Label27.Text,PurchaseQty:qtyinput_1.Text}))

 

The error occurs because that ModelNumber respects for text, but values return from combo box control are a table actually. 

 

In my formula, I assume that you only have one option selected for combo box control.

 

Regards,

Mona

Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

13 REPLIES 13
PowerAddict
Level 10

Re: Patch to update or create item with addition (+)

Try Inventory.PurchaseQty + Value(qtyinput_1.Text)

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution. Thanks!

Hardit Bhatia
https://thepoweraddict.com
PowerAddict
Level 10

Re: Patch to update or create item with addition (+)

Actually my bad, the problem might be in Inventory.PurchasrQty. What data type is this?

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution. Thanks!

Hardit Bhatia
https://thepoweraddict.com

Re: Patch to update or create item with addition (+)

@PowerAddict  it is 

Single line of text
PowerAddict
Level 10

Re: Patch to update or create item with addition (+)

Try
Sum(Inventory.PurchaseQty, Value(qtyinput_1.Text))

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution. Thanks!

Hardit Bhatia
https://thepoweraddict.com

Re: Patch to update or create item with addition (+)

@PowerAddict  now it is adding as a new record not updating.

 

Following how made it

 

If(ComboBox2_3.Selected.Value in Inventory.ModelNumber,Patch(Inventory,LookUp(Inventory,ModelNumber=ComboBox2_3.Selected.Value),{ModelNumber:ComboBox2_3.Selected.Value},{Brand:Label27.Text},{PurchaseQty:Sum(Inventory.PurchaseQty, Value(qtyinput_1.Text))},Patch(Inventory,Defaults(Inventory),{ModelNumber:ComboBox2_3.Selected.Value,Brand:Label27.Text,PurchaseQty:qtyinput_1.Text})))

PowerAddict
Level 10

Re: Patch to update or create item with addition (+)

The change you made shouldn't change if a new record gets created or an existing record gets updated. Are you saying this behavior changed?

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution. Thanks!

Hardit Bhatia
https://thepoweraddict.com

Re: Patch to update or create item with addition (+)

Yes brother @PowerAddict I am also really surprised to see that  

 

Still thinking on why behaved like that after I did that Sum change

 

Osmand

PowerAddict
Level 10

Re: Patch to update or create item with addition (+)

Copy and paste your before and after formula please.

Re: Patch to update or create item with addition (+)

@PowerAddict This is really interesting,

 

Old formula just to add and replaced is working, but after doing the change as per your suggestion it is adding only. Also gives an error

 

We are not touching the ID in the formula. Very strange. 

Annotation 2019-12-03 113008 2.jpg

Annotation 2019-12-03 113008.jpg

Helpful resources

Announcements
thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (5,008)