cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
carem
Helper III
Helper III

Can't create Collection using ClearCollect Function

I encountered a challenge when following the guidelines of this article.
In the Step: Writing the related schools into a collection

Faculty Field -> OnChange: 

ClearCollect( collSchools, { Schools: Filter( Schools, Faculty.Value = DataCardValue2.Selected.Value ) } )

Property Explanation

collSchoolsThis is our collection where all related schools for the selected faculty are written in to
SchoolsThis is the name of the column where the data is written in to
FilterThis is the function that filters values from a data set. The format of this function is as follows: Filter(source,logical_test)
SchoolsThis is the data set that we use in our filter. In this case, it is the Schools list we added as data source
Faculty.ValueThis is the value we are looking for in our data set. In this case, it is the Faculty lookup field in our Schools list
DataCardValue2.Selected.ValueThis is the selected faculty from our PowerApp

 

I follow this fomulas but the result is an empty collSchools Collection.

Here is my Form Setting

Screen Shot 2019-10-08 at 9.17.34 PM.png

And the OnChange of Faculty Dropdown:

Screen Shot 2019-10-08 at 9.18.52 PM.png

And the collSchools Collection: Empty School Column

Screen Shot 2019-10-08 at 9.19.26 PM.png

Can anyone help me resolve this problem?

11 REPLIES 11
Pstork1
Dual Super User III
Dual Super User III

DataCardValue2 is an arbitrary name provided by the system when you added the data card to the screen.  But in your image it shows you've renamed it to drpd_Faculty.  So the formula should read.

ClearCollect( collSchools, { Schools: Filter( Schools, Faculty.Value = drpd_faculty.Selected.Value ) } )

 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

@Thanks for the quick answer, @Pstork1.

But my setting is correct as you. You can see the picture I setting.

Pstork1
Dual Super User III
Dual Super User III

Are you sure that fields in the Schools list match (including case sensitivity) the entries in the Faculty dropdown list?  The collection is being created it just has no data in it.  So I suspect your filter statement is returning an empty record set.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Here is my Schools List. And I see everything match the setting in PowerApps (including case sensitivity)

Screen Shot 2019-10-08 at 9.46.44 PM.png

Pstork1
Dual Super User III
Dual Super User III

Try this for a quick test.  Replace the current statement with the following:

 

ClearCollect( collSchools, { Schools: Filter( Schools, Faculty.Value = "Faculty of Health" ) } )

See if that provides a collection.  YOu could also temporarily add a gallery to your form and set the Items collection to the following to make sure that you are getting a set of records back.

Filter( Schools, Faculty.Value = "Faculty of Health" )

I still think something has to be off in your Filter statement.

 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

I follow your instruction and have the result:

1/ Can't create a collection

2/ Can create a Gallery with 

Filter( Schools, Faculty.Value = "Faculty of Health" )

But it default display the Created By Column and ignore the Faculty Column.

Screen Shot 2019-10-08 at 10.02.32 PM.png 

What can I do next?

RezaDorrani
Dual Super User II
Dual Super User II

Hi @carem 

 

Create a label for test purpose

Set text property of label to

 

CountRows(Filter( Schools, Faculty.Value = DataCardValue2.Selected.Value ))

 

If count is 0, then your query is not correct

 

also try with 

CountRows(Filter( Schools, Faculty.Value = "hardcode a value here and check" ))

 

--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

Pstork1
Dual Super User III
Dual Super User III

It doesn't matter what shows in the Gallery.  The whole point was to make sure the filter works to return records.

 

If you take the other formula and put it in the OnSelect for a button then run the app and press the button do you get a collection?



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

@RezaDorrani 

I set 2 text labels to test your expression.

And both of them return 0.

Screen Shot 2019-10-09 at 10.03.03 AM.png

The warning:

Screen Shot 2019-10-09 at 10.03.49 AM.png

That means my query was wrong. But I couldn't detect any points.

 

@Pstork1 

I try the example of Microsoft:

ClearCollect( IceCream, { Flavor: "Strawberry", Quantity: 300 } )

and success.

Screen Shot 2019-10-09 at 10.08.23 AM.png

 

And I have discovered a serious problem with Preview Mode. I think it is the cause of this problem.

My Preview Function is not working. It's mean when I press F5 you can see my form like this:

Edit ModeEdit ModePreview ModePreview Mode

It may be that it cannot recognize the value of drpd_Faculty.Selected.Value. And return an empty Collection.
Follow Pstork1's advice, I create a button with OnSelect Property:

ClearCollect( collSchools, { Schools: Filter( Schools, Faculty.Value = "Faculty of Health" ) } )

And it's work.

But when I go back for  

ClearCollect( collSchools, { Schools: Filter( Schools, Faculty.Value = drpd_Faculty.Selected.Value ) } )

It does not work anymore.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,710)