Skip to main content
Community site session details

Community site session details

Session Id : X+lZmYnpUSmLMlYvpSS42M
Power Apps - Microsoft Dataverse
Answered

Stuck creating a collection

Like (0) ShareShare
ReportReport
Posted on 12 May 2020 15:58:27 by 23

Hello,

 

I'm following steps on how to create a collection in the docs.microsoft.com module called Use basic formulas to make better Power Apps canvas apps (here). It does not specifically say but it's implied that I use a Data table to create the collection. When following the steps I get the following error: "Behavior function in a non-behavior property. You can't use this property to change values elsewhere in the app." 

My question is, am I doing something wrong or is there a problem with the module?

Thank you,

DT

  • DT69 Profile Picture
    23 on 14 May 2020 at 08:56:24
    Re: Stuck creating a collection

    That makes complete sense. It appears that the course leaves out some detail. The articles you provided are also helpful. 

     

    Best,
    DT

  • Verified answer
    v-xida-msft Profile Picture
    on 13 May 2020 at 05:27:34
    Re: Stuck creating a collection

    Hi @DT69 ,

    Based on the issue that you mentioned, I think there is something wrong with location where you put your Collect or ClearCollect function in your canvas app.

     

    The Collect function or the ClearCollect function is a behavior function, which could not be used within Non-behavior property of a control. On your side, you should put your Collect function or ClearCollect function within Behavior property of a control. e.g. OnSelect property of a button.

     

    More details about behavior formula in PowerApps, please check the following article:

    https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/working-with-formulas-in-depth

     

    More details about usage of collection in PowerApps, please check the following article:

    https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/create-update-collection

     

    On your side, please add a button control in your app, set the OnSelect property to following:

    ClearCollect(
     Collection1, 
     {Name: "User1", Age: 30}, 
     {Name: "User2", Age35}
    )

    or

    Collect(
     Collection1, 
     {Name: "User1", Age: 30}, 
     {Name: "User2", Age35}
    )

     

    Please take a try with above solution, check if the issue is solved.

     

    Best regards,

  • Verified answer
    Drrickryp Profile Picture
    Super User 2024 Season 1 on 12 May 2020 at 22:14:57
    Re: Stuck creating a collection

    Hi @DT69 

    You are mistaken regarding how to use a datatable.  A datatable is a control that allows you to examine the data that already exists in a table or collection.  To create a table from raw data, you can use the Table() function like in the example in the documentation. Once the data is created it is stored in a temporary file called a collection by wrapping the Table in a Collect() or ClearCollect() function. In the example below Collect is used to store the data and the collection is named mydessert. but you could name it anything you want.  Remember  collections exist only in memory and are erased when the app is closed.  

     

     

    Collect(mydessert, Table({Name: "Chocolate", Price: "$ 3.95", 'Quantity on Hand':
    12, 'Quantity on Order': 10}, {Name: "Bread", Price: "$ 4.95",
    'Quantity on Hand': 34, 'Quantity on Order': 0}, {Name: "Water",
    Price: "$ 1.95", 'Quantity on Hand': 10, 'Quantity on Order':
    10})

     

     

    To execute the formula, place it in the OnSelect property of a button or icon.  When you push it, it creates the collection from the data in the table.  Then, when the button is pushed a collection called mydessert is created from the data. To view it, put a datatable or gallery control on the screen and set the Items property to: mydessert and you should see the following. Annotation 2020-05-12 151158.jpg

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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 637 Most Valuable Professional

#2
stampcoin Profile Picture

stampcoin 570 Super User 2025 Season 2

#3
Power Apps 1919 Profile Picture

Power Apps 1919 473

Featured topics