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 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:
  • Gochix Profile Picture
    1,937 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,937 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,937 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

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
11manish Profile Picture

11manish 393 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 278 Most Valuable Professional

Last 30 days Overall leaderboard