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 / Collect function is gi...
Power Apps
Suggested Answer

Collect function is giving 'Invalid argument type' error.

(1) ShareShare
ReportReport
Posted on by 6
I created a button that collects the values from a few text controls into a collection. Then, it uses a ForAll function to create another collection that adds an index value. That collection is then used to overwrite the original collection. I did this in order to dynamically have an index column in the collection, since I also have a button that is used to remove records from the collection. The collection is used as the data source for a gallery.
 
The code for the button is below:
 
Collect(Pay_Item_Inventory, {
    ID: 0,
    Description: Pay_Item_Desc_Input_1.Selected.Description,
    Stn_Lim: Stn_Lim_Input_1.Text,
    Side_Ln: Side_Ln_Input_1.Selected.Value,
    Qty: Qty_Input_1.Text,
    Unit: Qty_Unit_1.Text,
    Doc: Doc_Input_1.Text
});

Clear(Inventory_Indexed);

ForAll(Pay_Item_Inventory, 
    Collect(Inventory_Indexed, {
        ID: CountRows(Inventory_Indexed),
        Description: Description,
        Stn_Lim: Stn_Lim,
        Side_Ln: Side_Ln,
        Qty: Qty,
        Unit: Unit,
        Doc: Doc
        }
    )
);

ClearCollect(Pay_Item_Inventory, Inventory_Indexed);

Reset(Pay_Item_Desc_Input_1);
Reset(Stn_Lim_Input_1);
Reset(Side_Ln_Input_1);
Reset(Qty_Input_1);
Reset(Doc_Input_1);
Everything worked perfectly yesterday. However, when I logged in today, I'm suddenly getting an error in the Collect function, that the specifed collection is an Invalid Argument Type. Furthermore, every reference to the collection throughout the app throws the same error. 
 
I was able to narrow the issue down to the first Collect function in the above code. When I remove that portion of the code, everything works. However, I need to be able to collect the values, so removing this portion of the code is not acceptable.
 
I also noticed that, for some reason, the Pay_Item_Inventory collection is appearing in the Variables pane as "Variable: []" instead of "Table: 0 rows" (screenshot below) like the rest of the empty collections.
 
 
I've tried using ClearCollect(Pay_Item_Inventory, Blank()) in the OnStart property, but I get the same error that Pay_Item_Inventory is an "Invalid Argument Type."
 
I'm not sure why it suddenly stopped working, but any assistance would be appreciated.
 
Screenshot 2025-09-11 100242.png
Categories:
I have the same question (0)
  • Suggested answer
    Michael E. Gernaey Profile Picture
    53,963 Moderator on at
     
    It says it a variable, not a collection (aka Table), so you cannot do a Collect on it. Something has changed it.
     

    If these suggestions help resolve your issue, Please consider Marking the answer as such and also maybe a like.

    Thank you!
    Sincerely, Michael Gernaey
     
     
  • Suggested answer
    Pstork1 Profile Picture
    69,485 Most Valuable Professional on at
    Do  a Search on the app for Pay_Item_Inventory to make sure its only used as a Collection.  It may be referenced somewhere in your app as a Variable.  You can't use the same name for a variable and a Collection. I suspect its used in conjunction with a Set or an UpdateContext somewhere in the app.  Doing a Clear() on the collection that shows up as a variable array can remove the existing variable.

    ----------------------------------------------------------------------------------
    If this Post helped you, please click "Does this answer your question" and give it a like to help others in the community find the answer too!

    Paul Papanek Stork, MVP
    Blog: https://www.dontpapanic.com/blog
     
  • LC-23041845-0 Profile Picture
    6 on at
    @Pstork1: Thanks for the suggestion. Unfortunately, the search didn't return any cases where the Pay_Item_Inventory is being used as a variable. I also don't have any functions that use Set or UpdateContext. Other than the code I posted, the only other reference is:
     
    Remove(Pay_Item_Inventory, ThisItem
     
     I think I may have found a clue. When I change the keys for Inventory_Indexed in the ForAll function, the error goes away. But again, that kinda messes up what I'm trying to accomplish. I want to overwrite the Pay_Item_Inventory collection with the Inventory_Indexed collection, so the schema needs to be the same.
     
    @Michael E. Gernaey: This is what is confusing me. I'm not sure what could be causing it to cast as a variable, since I only ever reference it as a collection.
    Screenshot 2025-09-11 140041.png
    Screenshot 2025-09-11 140129.png
  • Pstork1 Profile Picture
    69,485 Most Valuable Professional on at
    The schemas tend to persist once they are established even if you remove the code later.  Try adding 
    Clear(Pay_Item_Inventory) at the start of the onSelect to clear out everything related to that name and re-establish it with the ClearCollect().  ClearCollect removes all the records but retains any schema.

    ----------------------------------------------------------------------------------
    If this Post helped you, please click "Does this answer your question" and give it a like to help others in the community find the answer too!

    Paul Papanek Stork, MVP
    Blog: https://www.dontpapanic.com/blog
     
  • WarrenBelz Profile Picture
    155,427 Most Valuable Professional on at
    I will throw in an alternative, much simpler way of doing what you want to do (have the ID sequentially numbered according to the records in the colleciton). You can still collect as you are now
    Collect(
       Pay_Item_Inventory,
       {
          ID: 0,
          Description: Pay_Item_Desc_Input_1.Selected.Description,
          Stn_Lim: Stn_Lim_Input_1.Text,
          Side_Ln: Side_Ln_Input_1.Selected.Value,
          Qty: Qty_Input_1.Text,
          Unit: Qty_Unit_1.Text,
          Doc: Doc_Input_1.Text
       }
    );
    but then when you are ready to index the ID, do this
    With(
       {_Data: Pay_Item_Inventory},
       ClearCollect(
          Pay_Item_Inventory,
          ForAll(
             Sequence(CountRows(_Data)),
             Patch(
                Index(
                   _Data,
                   Value
                ),
                {ID: Value}
             )
          )
       )
    );
    Also if you set the Reset property of all those controls to varReset, you can do this at the end of the code
    UpdateContext({varReset: true});
    UpdateContext({varReset: false});
    Make sure you put this code in before you set the control properties
     
    Please ✅ 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♥.
    Visit my blog
    Practical Power Apps    LinkedIn   

     
  • LC-23041845-0 Profile Picture
    6 on at
    @Pstork1 Unfortunately, that didn't work out either. However, I was able to fix it by changing the keys in the collections. I'm not sure why that was the issue. I am pulling the data from a spreadsheet, where the columns are the same as the keys I was using in the collection. Maybe that was causing some kind of mix up? I'm not sure, but at least it's working now. 
     
    I appreciate you taking the time to help me with this issue!
     
    @WarrenBelz Thanks for the suggestions! I'll definitely give this a try.
  • Pstork1 Profile Picture
    69,485 Most Valuable Professional on at
    I'm assuming the Data Source you are using from Excel is named Pay_Item_Inventory as well. I find that its not a good idea to name a collection the same as another variable or Data Source. So that may explain some of the conflicts also. Glad you found a solution.

    ----------------------------------------------------------------------------------
    If this Post helped you, please click "Does this answer your question" and give it a like to help others in the community find the answer too!

    Paul Papanek Stork, MVP
    Blog: https://www.dontpapanic.com/blog
     
     
  • Michael E. Gernaey Profile Picture
    53,963 Moderator on at
     
    Just curious if you don't mind me asking. How did you search exactly?
     
    Using the same names is fine, but when needed you should make sure to Scope it to make sure its using the right data. so in your For All I would have scoped an Alias for your Collection so that you would have in your collect stated myalias.Column not just Column where the names are the same.
     
    for something internally to change from a Collection to a Variable, it can happen realistically only with a Set. However variables can be finicky. 
     
    Many times I see people not realizing that the variable name is being used in multiple places and with different values.
     
    It seems you have many different answers, but i believe if you simply scoped it it would have resolved initially, but it would have been interesting :-) to use Live Monitor to had seen the actual data manipulation as to why it changed (you said it was good before, so a table/collection to not).
     
     
     
     
  • WarrenBelz Profile Picture
    155,427 Most Valuable Professional on at
    A quick follow-up to see if you received the answer you were looking for from anyone who responsed ?
     
    Please ✅ 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 answering Yes to Was this reply helpful?
    Visit my blog
    Practical Power Apps    LinkedIn

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 839

#2
Valantis Profile Picture

Valantis 533

#3
Haque Profile Picture

Haque 412

Last 30 days Overall leaderboard