cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Regular Visitor

Stuck creating a collection

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

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Super User III
Super User III

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

View solution in original post

Highlighted
Community Support
Community Support

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,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Highlighted
Super User III
Super User III

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

View solution in original post

Highlighted
Community Support
Community Support

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,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Highlighted

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

 

Best,
DT

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Users online (9,478)