cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
pablik01
Helper III
Helper III

Adding a quantity to an existing one in the collection

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})
1 ACCEPTED SOLUTION

Accepted Solutions

With({
aLookup: LookUp(Zamowienie, nazwa_asortymentu_do_dodania.Text = Nazwa)},
        If(IsBlank(aLookup),
            Patch(Zamowienie, Defaults(Zamowienie),
            {
                Ind: ThisItem.Indeks,
                Grupa: ThisItem.Grupa,
                Nazwa: ThisItem.'Nazwa asortymentu',
                Jednostka: ThisItem.'j.m.',
                Liczba: Value(liczba.Text)
            }
            ),
            Patch(Zamowienie, aLookup,
            {
                Ind: ThisItem.Indeks,
                Grupa: ThisItem.Grupa,
                Nazwa: ThisItem.'Nazwa asortymentu',
                Jednostka: ThisItem.'j.m.',
                Liczba: aLookup.Liczba + Value(liczba.Text)
            } 
            )
        )
    )

View solution in original post

16 REPLIES 16
Gochix
Solution Sage
Solution Sage

 

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)
            } 
            )
        )
    )

"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

 

@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)
            } 
            )
        )
    )

 

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)
            } 
            )
        )
    )

 

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)
            } 
            )
        )
    )

 

no bugs, it just doesn't do anything

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
Helper III
Helper III

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

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)
            } 
            )
        )
    )

 

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (3,305)