cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DT69
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
Drrickryp
Super User
Super User

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

v-xida-msft
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
Drrickryp
Super User
Super User

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

v-xida-msft
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.

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
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Users online (1,772)