web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Adding the quantity of...
Power Apps
Unanswered

Adding the quantity of two identical products in a collection

(0) ShareShare
ReportReport
Posted on by 98


Good afternoon

Someone help me?

I am adding products to a collection and I would like that when 2 equal products were added, only 1 would appear and the value would add up to the total value of the products

Categories:
I have the same question (0)
  • Gochix Profile Picture
    1,935 Moderator on at

    Hi @beatrizmoura26 ,

     

    How are you adding these products to your collection?

    If that's via Patch then you have to check if there is any records already in collection with this Products ID / Name.

     

    If(IsBlank(LookUp(DataSource,ProductID = Value(ProductIDTextLabel.Text)),
     Patch(DataSource, Defaults(DataSource),
     {
     Product_Value: Value(ProductValueTextLabel.Text)
     }
     ),
     Patch(DataSource,LookUp(DataSource,ProductID = Value(ProductIDTextLabel.Text)),
     {
     Product_Value: Sum(Filter(DataSource, ProductID = Value(ProductIDTextLabel.Text)))
     }
     )
    )
    )

     

    As you haven't said how you are adding new records in collection then this would be for a manual use.

    If needed for Gallery then the code would have to change a bit.


    _____________________________________________________________________________________
    Please give a thumbs up if I resolved your issue! Please click Accept as Solution to close the topic!

  • beatrizmoura26 Profile Picture
    98 on at


    I added a check button inside a gallery, and inside the oncheck I added a collection

    Collect(
    colProdTranf,
    Filter(
    Product,
    CallID = ThisItem.ID
    )
    );

    Inside this collection I have 3 fields

    code
    product
    the amount

    and I wish that if the collection already had a product with the same code, it would just add the amount

  • Gochix Profile Picture
    1,935 Moderator on at

    You can try this:

    If(
     IsBlank(
     LookUp(colProdTranf,ID=ThisItem.ID)
     ),
     Collect(colProdTranf,ThisItem),
     Patch(colProdTranf,LookUp(colProdTranf,ID = ThisItem.ID),
     {
     Amount:LookUp(colProdTranf,ID = ThisItem.ID).Amount + 1
     }
     )
    )

    _____________________________________________________________________________________
    Please give a thumbs up if I resolved your issue! Please click Accept as Solution to close the topic!

  • beatrizmoura26 Profile Picture
    98 on at



    It didn't work, it just adds 1 to the quantity and not the value that is in the quantity column.

    Ex.: PRODUCT 1 WITH QUANTITY 10

    PRODUCT 1 SELECTED AGAIN WITH QUANTITY 5

    He should add and leave a line with PRODUCT 1 WITH QUANTITY 15

    But with this function, it is actually adding 1 more to the first included product, making the amount equal to 11

  • Gochix Profile Picture
    1,935 Moderator on at

    try this then please:

    If(
     IsBlank(
     LookUp(colProdTranf,ID=ThisItem.ID)
     ),
     Collect(colProdTranf,ThisItem),
     Patch(colProdTranf,LookUp(colProdTranf,ID = ThisItem.ID),
     {
     Amount:LookUp(colProdTranf,ID = ThisItem.ID).Amount + ThisItem.Amount
     }
     )
    )


    _____________________________________________________________________________________
    Please give a thumbs up if I resolved your issue! Please click Accept as Solution to close the topic!

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard