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 / Power Apps Gallery Ite...
Power Apps
Answered

Power Apps Gallery Item Price Inconsistency in Cart Operation

(0) ShareShare
ReportReport
Posted on by 27

Hello, Power Apps community,

I'm developing a shopping cart application in Power Apps with a peculiar issue related to how items are added and updated in the cart. The application consists of two galleries:

  1. Inventory Gallery: Sources its data from a SharePoint list called "Inventory(VendingMachine)".
  2. Cart Gallery: Maintains its data in a local collection called "ItemQuantities".

Each item in the cart gallery includes '+' and '-' buttons for adjusting item quantities.

Issue: When I first add an item to the cart, the '+' and '-' buttons do not update the TotalPrice correctly, sometimes setting it to zero. However, clearing the collection (the shopping cart) and adding an item again causes the buttons to work as expected.

Conversely, changing the reference from ItemPrice to Price in the button functionality corrects the issue on the first addition—where TotalPrice updates correctly—but subsequent additions after clearing the cart behave unexpectedly.

Code for Adding Items to Cart: 

 

 

 

If(
 LookUp('Inventory(VendingMachine)', Title = ThisItem.Title).'Quantity Available' > Coalesce(LookUp(ItemQuantities, Title = ThisItem.Title).QuantitySelected, 0),
 If(
 IsEmpty(Filter(ItemQuantities, Title = ThisItem.Title)),
 Collect(
 ItemQuantities, 
 {
 Title: ThisItem.Title, 
 QuantitySelected: 1,
 ItemPrice: ThisItem.Price,
 TotalPrice: ThisItem.Price,
 ItemImageURL: ThisItem.'Image URL'
 }
 ),
 Patch(
 ItemQuantities, 
 LookUp(ItemQuantities, Title = ThisItem.Title), 
 {
 QuantitySelected: LookUp(ItemQuantities, Title = ThisItem.Title).QuantitySelected + 1,
 TotalPrice: (LookUp(ItemQuantities, Title = ThisItem.Title).QuantitySelected + 1) * ThisItem.Price
 }
 )
 ),
 Notify("Not enough stock available", NotificationType.Error)
)

 

 

Code for '+' Button:

 

If(
 LookUp('Inventory(VendingMachine)', Title = ThisItem.Title).'Quantity Available' > ThisItem.QuantitySelected,
 Patch(
 ItemQuantities,
 LookUp(ItemQuantities, Title = ThisItem.Title), 
 {
 QuantitySelected: ThisItem.QuantitySelected + 1,
 TotalPrice: (ThisItem.QuantitySelected + 1) * ThisItem.ItemPrice
 }
 ),
 Notify("Not enough stock available", NotificationType.Error)
)

 

 

Question: What could be causing this inconsistency in how the TotalPrice is updated, depending on whether it's the first addition or after clearing the cart? How can I ensure consistent behavior regardless of the addition order?

Any insights or suggestions would be greatly appreciated!

Categories:
I have the same question (0)
  • Verified answer
    Eldor488 Profile Picture
    27 on at

    I fixed the issue, the workaround I found is that I calculated the price looking up the price from the original data source rather than the one saved in the collection. 

    • Old Code: 

     

    TotalPrice: (ThisItem.QuantitySelected + 1) * ThisItem.ItemPrice

     

    • New Code: 

     

    TotalPrice: (ThisItem.QuantitySelected + 1) * LookUp('Inventory(VendingMachine)', Title = ThisItem.Title).Price

     

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 385

#2
Vish WR Profile Picture

Vish WR 367

#3
timl Profile Picture

timl 340 Super User 2026 Season 1

Last 30 days Overall leaderboard