Hi @Andyh1 ,
Ok, so there's a few ways to do it - you may need to pick one that fits with the experience you're trying to create - also you need to decide on some preferences, such as;
- Do you want to rather pack all newgoods onto one shelf, or would you prefer to first fill up remaining space on other shelves?
- Do you need to keep a running total IN the gallery, or can it live outside the Gallery?
Your preferences may change the answer, but let's make some assumptions and start with an example for you to start tweaking.
Example assumptions:
- Your Gallery is called "ShelfGallery"
- The checkbox inside the Gallery is called "packedCheckBox"
- NewGoods is a context variable
This is just a quick and dirty way just to illustrate the logic.
Add a label to your page (not the gallery, otherwise you'll get a circular reference error) - call it lblRunningTotal and set its Text: property to;
NewGoods - Sum(Filter(ShelfGallery.AllItems, packedCheckBox.Value), SpaceAvail)
This will now Sum the available space of the checked items in the Gallery and subtract it from NewGoods. NOTE: it does not change the value of NewGoods - it's just uses it to calculate a remaining value based on what's been checked.
But we may also want to stop people from continuing to 'pack' when there are no more goods left to pack, so we can disable the CheckBoxes as soon as the number of NewGoods reaches 0 or less;
Set the DisplayMode: property of packedCheckBox to;
If(Value(lblRunningTotal.Text) <=0,
If(packedCheckBox.Value,
DisplayMode.Edit, DisplayMode.Disabled),
DisplayMode.Edit)
So, if the packing calculation of NewGoods is less than or equal to 0, then we've packed all the items. In that case Disable all checkboxes that haven't already been checked. If you want to reorder or pack differently, you must first uncheck (unpack) from one of the shelves.
So much for the quick and dirty - but you probably still want to update NewGoods to zero, or whatevers left over when you're done. May also want to update the remaining space of each shelf once it's packed.
For a more efficient performance and flexible function solution, you may want to keep an indexed collection of shelves that are being 'packed' and the space that's being used on them. You can do this using the packedCheckBox OnCheck: and OnUncheck: properties to populate and remove entries in a collection, but you'll need to keep track of how much space on the current shelf was used in order to update it's remaining space value as well.
You can also do things like sort and filter your ShelfGallery to show items with the most space first, or filter the gallery where the remaining space is precisely the same as the amount of NewGoods.
A lot will depend on your preferences - but this should give you enough to get started 
Hope it helps,
RT