Skip to main content

Notifications

Community site session details

Community site session details

Session Id : B9nHsoRhZTbqOzTO7+s2r9
Power Apps - Building Power Apps
Answered

Shopping cart

Like (0) ShareShare
ReportReport
Posted on 4 Mar 2020 16:11:13 by 19

Even though I just started learning how to build Powerapps, I have made an pretty good app for registering inventory.

Now I don't like to ask for help every time, I always try to search for solutions myself if I'am stuck at something. This works pretty good, but I can't find an solution for this thing (I don't know what to search for exactly though):

 

I have an dropdown list where the user can choose an item and than an input box to fill in the amount for that item.

All items are added to an collection called 'InventoryList'. That gallery is directly shown besides the input part.

The current situation is that, if an item already exists in the gallery, the new amount is put in as an seperate item.
I like to have it so that it add up the amount of the item instead of putting everything in as seperate items, even when that same item is already in the gallery.

 

So basicly, in the current situation: If for example Item1 is already in the gallery, and I add that item again, but whith another amount, I end up with having Item1 two times in the gallery, with two different amounts.

I like to have: If I add Item1 to the gallery, but it already exists, it only add up the amount of that item.


What I have now for the default on the submit button is: 

 

Collect (InventoryList; {Item: I_Item.Selected.Title; Amount: I_Amount.Text; Photo: Filter_dropdown_photo.SelectedText.Value});;

 

And than I have an gallery showing the items in StockList. 

As it is, I'm not writing the records storage location, I just make an collection and than the user can have it send by email at the end of the day, by cliking another button.

  • RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on 04 Mar 2020 at 19:40:56
    Re: Shopping cart

    @alexanderb1 

    Excellent!!

  • alexanderb1 Profile Picture
    19 on 04 Mar 2020 at 19:36:24
    Re: Shopping cart

    @RandyHayes 

     

    That worked, thank you very much!

  • Verified answer
    RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on 04 Mar 2020 at 19:15:14
    Re: Shopping cart

    @alexanderb1 

    Sorry I seemed to have had a typo in the formula before...the disadvantage of free-typing formulas outside of PowerApps.

    With({lclItem:LookUp(InventoryList; Item=I_Item.Selected.Title)};
    
     If(IsBlank(lclItem.Item);
     Collect(InventoryList; 
     {Item:I_Item.Selected.Title; 
     Amount:I_Amount.Text;
     Photo: Filter_dropdown_photo.SelectedText.Value}
     );
     UpdateIf(InventoryList;
     Item=lclItem.Item; 
     {Amount:Value(lclItem.Amount) + Value(I_Amount.Text)})
     )
    )

    (Also added a little value conversion so the addition works properly)

    I've double checked the above, but I might still be off on a particular semicolon or parenthesis. 

    See if that goes for you.

  • alexanderb1 Profile Picture
    19 on 04 Mar 2020 at 19:03:25
    Re: Shopping cart

    It's just collecting on this single screen, not used on other places. So it's just creating the list on that screen and than I have an option build in to send that list by email.

  • RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on 04 Mar 2020 at 19:01:33
    Re: Shopping cart

    @alexanderb1 

    That almost looks like this is the ONLY place in your app that you are "Collecting" to the InventoryList collection.

    Are you using ("Collecting" or "ClearCollecting") the InventoryList collection in another place?

     

  • alexanderb1 Profile Picture
    19 on 04 Mar 2020 at 18:48:28
    Re: Shopping cart

    Thanks, but it's trowing a lot of errors for this one, starting with LookUp having wrong arguments, also it doesn't seem to recognize the collection. 

     

    PowerApps_Errors.jpg

     

  • RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on 04 Mar 2020 at 18:03:14
    Re: Shopping cart

    @alexanderb1 

    Try changing your formula to the following:

    With({lclItem:Lookup(InventoryList; Item=I_Item.Selected.Title)};
     If(IsBlank(lclItemVal.Item);
     Collect(InventoryList; 
     {Item: I_Item.Selected.Title; 
     Amount: I_Amount.Text; 
     Photo: Filter_dropdown_photo.SelectedText.Value
     }
     );
     UpdateIf(InventoryList; 
     Item=lclItem.Item; 
     {Amount: lclItem.Amount + Value(I_Amount.Text)}
     )
    )

     

    This will update an existing record if it is there.

    I hope this is helpful for you.

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,668 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,004 Most Valuable Professional

Leaderboard
Loading started