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 a quantity to a...
Power Apps
Answered

Adding a quantity to an existing one in the collection

(0) ShareShare
ReportReport
Posted on by

Hello, can you help me with the code, I broke something and I do not know what: if an item already exists in the collection, I would like not to add a new one to it, but only add the quantity to the existing one

Patch(Zamowienie;LookUp(Zamowienie;Nazwa=Nazwa);{Liczba:Value(liczba.Text)+liczba.Text})
Categories:
I have the same question (0)
  • Gochix Profile Picture
    1,937 Moderator on at

     

    Hi @pablik01 ,

    Where Nazwa = Nazwa here you usually would need to check ID or some kind of checker to see if this record exist in collection/list.

    By this I would say now you only check Nazwa equals Nazwa. So no specific record.

    With({
    aLookup: LookUp(Zamowienie, Nazwa = Nazwa)},
     If(IsBlank(aLookup),
     Patch(Zamowienie, Defaults(Zamowienie),
     {
     Liczba: Value(liczba.Text)
     }
     ),
     Patch(Zamowienie, aLookup,
     {
     Liczba: Value(liczba.Text)
     } 
     )
     )
     )
  • pablik01 Profile Picture
    on at

    "Nazwa" is a column in the collection, and now I have to compare that to the name in the gallery? I would like to understand it, but I don't know how to go about it. i have two button galleries in one adds a record to the other

    pablik01_0-1660458819388.png

     

  • Gochix Profile Picture
    1,937 Moderator on at

    @pablik01 ,

    Let's imagine your name in the gallery that you need to compare in the column "Nazwa" is in text Label = Label1.Text

     

    Then you can compare it with column "Nazwa" and get exact match and by that change quantity for that record.

     

     

    With({
    aLookup: LookUp(Zamowienie, Label1.Text = Nazwa)},
     If(Not(IsBlank(aLookup)),
     Patch(Zamowienie, aLookup,
     {
     Liczba: Value(liczba.Text)
     } 
     )
     )
     )

     

  • pablik01 Profile Picture
    on at

    ok so "Nazwa" is a column in my collection and"nazwa_asortymentu_do_dodania "is a label in the gallery, I have something like this but it doesn't work

     

    With({
    aLookup: LookUp(Zamowienie; nazwa_asortymentu_do_dodania.Text = Nazwa)};
     If(Not(IsBlank(aLookup));
     Patch(Zamowienie; aLookup;
     {
     Liczba: Value(liczba.Text)
     } 
     )
     )
     )
  • Gochix Profile Picture
    1,937 Moderator on at

     

    Is there any errors with this?

    By "it doesn't work" is not clear what doesn't work.

    With({
    aLookup: LookUp(Zamowienie, nazwa_asortymentu_do_dodania.Text = Nazwa)},
     If(Not(IsBlank(aLookup)),
     Patch(Zamowienie, aLookup,
     {
     Liczba: Value(liczba.Text)
     } 
     )
     )
     )

     

  • pablik01 Profile Picture
    on at

    no bugs, it just doesn't do anything

  • Gochix Profile Picture
    1,937 Moderator on at

    Is the collection "Zamowienie" in your PowerApp or is this a SharePoint collection?

    If this is SharePoint collection then you should refresh the collection by collecting it again to see a change. 

  • pablik01 Profile Picture
    on at

    not SharePoint. maybe I'll explain again. I have a gallery with a list of goods. In Textinput, I enter how much of a given product I want to order and add it to the collection using the button. And now If I add the same product twice, I currently have two records in the collection in my collection, I would like them to add up. In addition, maybe you can help in one more case, because I have been struggling with it for 2 hours and it seems simple.
    in the gallery (before adding to the collection) I have this InputText where I enter the amount, I want to make a button that adds input text +1 to this, I have already tried various solutions from the forum but it does not work ... no errors but it does not work

  • Gochix Profile Picture
    1,937 Moderator on at

    This should now add new record if product doesn't exist in collection and sum the Liczba with previous record + liczba.text

     

    With({
    aLookup: LookUp(Zamowienie, nazwa_asortymentu_do_dodania.Text = Nazwa)},
     If(IsBlank(aLookup),
     Patch(Zamowienie, Defaults(Zamowienie),
     {
     Liczba: Value(liczba.Text)
     }
     ),
     Patch(Zamowienie, aLookup,
     {
     Liczba: aLookup.Liczba + Value(liczba.Text)
     } 
     )
     )
     )

     

  • pablik01 Profile Picture
    on at

    wow ok, sum, only now if the record doesn't exist i miss this:

    Collect(Zamowienie;{Grupa:ThisItem.Grupa;Nazwa:ThisItem.'Nazwa asortymentu';Liczba:liczba.Text;Jednostka:ThisItem.'j.m.';Ind:ThisItem.Indeks});;

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 335 Most Valuable Professional

#2
11manish Profile Picture

11manish 165

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 96 Super User 2026 Season 1

Last 30 days Overall leaderboard