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 / use Power apps to mana...
Power Apps
Answered

use Power apps to manage inventory by First in First out

(1) ShareShare
ReportReport
Posted on by 107
Does anyone utilize Power Apps to manage inventory and deduct inventory quantities based on the First-In, First-Out (FIFO) method?
For example: 
Power apps gallery filter result that I want to A to ship out  quantity 11  and C to ship out quantity 2 , only ship toggled items.  
In the inventory SharePoint list, there are the following items. I need to deduct quantities from the inventory using a First-In, First-Out (FIFO) approach.  what is, recurrence to check the gallery toggled from first Item, A and then to deduct the inventory A starting from earlier created item. this example is 2025/1/1 item first to deduct 1, and next deduct 3, and 6 until deduct 11.  see result inventory. 
 
initial inventory
Name                    quantity            created date
A                            1                       2025/1/1
A                            3                        2025/3/2
A                            6                        2025/4/1
A                           3                         2025/6/3
B                          2                          2025/1/2
C                          3                          2025/5/1
 
result inventory 
Name                    quantity            created date
A                            0                       2025/1/1
A                            0                       2025/3/2
A                            0                        2025/4/1
A                           2                         2025/6/3
B                          2                          2025/1/2
C                          1                         2025/5/1
 
Categories:
I have the same question (0)
  • Suggested answer
    MS.Ragavendar Profile Picture
    6,961 Super User 2026 Season 1 on at
     
    Filter Gallery with Toggles - Ensure your gallery shows only items where a toggle (Toggle_Ship) is enabled.

    Filter(InventoryList, Toggle_Ship.Value = true)
     
    You need to write a loop in Power Apps using a ForAll with a nested loop (or recursive Patch approach) to perform FIFO deduction.
     
    ✳️ Sample Power Fx logic outline:
     
    // Suppose we have a collection of items to ship, like:
    // [{Name:"A", QuantityToShip:11}, {Name:"C", QuantityToShip:2}]
    ForAll(colShipList,
        With(
            {
                remainingQty: QuantityToShip,
                inventoryItems: Sort(Filter(InventoryList, Name = ThisRecord.Name && Quantity > 0), CreatedDate, Ascending)
            },
            ForAll(inventoryItems,
                If(remainingQty > 0,
                    With(
                        {
                            deductAmount: Min(remainingQty, ThisRecord.Quantity)
                        },
                        Patch(InventoryList, ThisRecord, {Quantity: ThisRecord.Quantity - deductAmount});
                        Set(remainingQty, remainingQty - deductAmount)
                    )
                )
            )
        )
    )
     
    Recurrence (if applicable)

    If you want this to happen automatically, use Power Automate (Flow) to:
    • Trigger periodically (daily/weekly).
    • Read toggled items from SharePoint.
    • Perform FIFO deduction via flow logic or call Power Apps function.
    🏷️ Please tag me @MS.Ragavendar if you still have any queries related to the solution or issue persists.
    Please click Accept as solution if my post helped you solve your issue and help others who will face the similar issue in future.
    ❤️ Please consider giving it a Like, If the approach was useful in other ways.
  • Henryzhou Profile Picture
    107 on at
    @MS.Ragavendar  I have tried your solution, unfortunately like other solution generated by AI that has the issue on Patch  below it shows error, The specified column 'deductAmount' does not exist.
    [
    Patch(InventoryList, ThisRecord, {Quantity: ThisRecord.Quantity - deductAmount});  
        
     
                  Set(remainingQty, remainingQty - deductAmount)   for this set it shows error 
     
    This function cannot be invoked within ForAll.
    ].
     
     
  • WarrenBelz Profile Picture
    155,283 Most Valuable Professional on at
    I was doing some work on this earlier and @MS.Ragavendar has responded since. The one piece missing here (and apologies @MS.Ragavendar if you were going to go this way), but you are correct that you cannot set a Variable inside a ForAll statement, however you can add to a Collection. Using most of the good code already provided, I have added this function
    ClearCollect(
       colOrder,
       {Remain: Value(YourTextBox.Text)}
    );
    ForAll(
       colShipList,
       With(
          {
             remainingQty: Last(colOrder).Remain,
             inventoryItems: Sort(
                Filter(
                   colShipList,
                   Name = YourNameLabel.Text && Quantity > 0
                ),
                CreatedDate,
                SortOrder.Ascending
             )
          },
          ForAll(
             inventoryItems As _Items,
             If(
                remainingQty > 0,
                With(
                   {
                      deductAmount: Min(
                         remainingQty,
                         _Items.Quantity
                      )
                   },
                   Patch(
                      colShipList,
                      LookUp(
                         colShipList,
                         CreatedDate = _Items.CreatedDate
                      ),
                      {Quantity: _Items.Quantity - deductAmount}
                   );
                   Collect(
                      colOrder,
                      {Remain: remainingQty - deductAmount}
                   )
                )
             )
          )
       )
    )
     
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn   
  • Henryzhou Profile Picture
    107 on at
    @WarrenBelz Hi Warren, Thanks so much for your help. it help to close successful. 
     
    Follow your codes, I have got two issue. 
     
    1, Looks like only can ship one item at one time. I want to check A and C together to ship all of them by hit the button one once.
    2, The variable "Remain" --remain quantity from collection colOrder that looks like out of loop then the result as below example. if I checked C and hit the ship then right side inventory list will deduct the 1 from C ID 6 first and then deduct 2 from C ID7, it suppose to deduct 1 from C ID7. 
    I have posted code below please help to correct, appreciate your help.
     
     
     
    Code as below on SHIP button: 
     
    ClearCollect(
        colOrder,
        ForAll(
        Filter(Gallery11.AllItems,Toggle1.Checked=true),
         {
                ProdName: ThisRecord.'Product Name',
                 Remain: Value(ThisRecord.'Ship quantity')
            }
        )
    );
     
    ForAll(
       colOrder,
       With(
          {
             remainingQty: Last(colOrder).Remain,
             inventoryItems: Sort(
                Filter(
                   库存数,
                   Title =ProdName && Quantity > 0
                ),
                ID,
                SortOrder.Ascending
             )
          },
          ForAll(
             inventoryItems As _Items,
             If(
                remainingQty > 0,
                With(
                   {
                      deductAmount: Min(
                         remainingQty,
                         _Items.Quantity
                      )
                   },
                   Patch(
                      库存数,
                      LookUp(
                         库存数,
                        ID = _Items.ID
                      ),
                      {Quantity: _Items.Quantity- deductAmount}
                   );
                   Collect(
                      colOrder,
                      {Remain: remainingQty - deductAmount}
                   )
                )
             )
          )
       )
    )
  • Verified answer
    WarrenBelz Profile Picture
    155,283 Most Valuable Professional on at
    Firstly, this is "best effort" - you are pushing the boundaries of nested loops here
    ClearCollect(
       colRemain,
       {Remain: 0}
    );
    ForAll(
       Filter(
          Gallery11.AllItems,
          Toggle1.Value
       ) As _Orders,
       Collect(
          colRemain,
          {Remain: Value(_Orders.tiQuantity.Text)}
       );
       With(
          {
             _Inventory: Sort(
                Filter(
                   YourSPList,
                   Name = _Orders.Name && Quantity > 0
                ),
                CreatedDate,
                SortOrder.Ascending
             )
          },
          ForAll(
             _Inventory As _Items,
             With(
                {_Remaining: Last(colRemain).Remain},
                If(
                   _Remaining > 0,
                   With(
                      {
                         _Deduction: Min(
                            _Remaining,
                            _Items.Quantity
                         )
                      },
                      Patch(
                         YourSPList,
                         LookUp(
                            YourSPList,
                            CreatedDate = _Items.CreatedDate
                         ),
                         {Quantity: _Items.Quantity - _Deduction}
                      );
                      Collect(
                         colRemain,
                         {Remain: _Remaining - _Deduction}
                      )
                   )
                )
             )
          )
       )
    )
     A couple of things I have used here
    • Gallery11 is the gallery containing the toggle Toggle1 and the quantity text input 'tiQuantity'
    • YourSPList is the SharePoint List you refer to with fields Name and Quantity and CreatedDate
     
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn   
  • Henryzhou Profile Picture
    107 on at
    Hi Warren, @WarrenBelz Thank you very much for your help. Added the Colremain first and out of the loop that contributed to the success. I sincerely appreciate your help.
    below is example, Hopefully, this will be helpful to anyone who is experiencing difficulties with the inventory FIFO scenario using Power Apps.
      Gallery selected A and C,  quantity 10 and 5
    and the result should as below
    A   5-> 0
    A   4->0
    A   6->5 
     
    C  1->0
    C 2->0
    C 6->4
     
    Actual Result:
     
     
  • WarrenBelz Profile Picture
    155,283 Most Valuable Professional on at
    Glad you got it sorted - colRemain was there before, but called (probably confusing) colOrder. I wrapped the earlier code inside an additional ForAll on the Gallery and changed a number of the references to naming conventions that more accurately reflected what they were doing.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 1,055

#2
Valantis Profile Picture

Valantis 666

#2
11manish Profile Picture

11manish 666

Last 30 days Overall leaderboard