cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
BarnBrat
New Member

How to Create Collection Based on If statement

I have a gallery and several filters, searches and all is working fine, however I want to put the records into a collection and I cannot for the life of me figure out how to put the results of the IF statement into a collection. Everything I try gives me an error. If I try to wrap the Filter statement in a Clear Collect, I get this error: 

BarnBrat_0-1635864147224.png

 

 

Basically I want to create a collection and be able to assign whatever the results of this IF statement are to the collection so that I can reference the collection elsewhere. Any ideas as to where I am going wrong?

 

Here is the If statement that is on the galARSTRecords.This:

If(ddSearchBy.Selected.Value = "Check Number" And ddFilter.Selected.Result = "All",
Filter('ARST Check Manager',StartsWith('Check Number',txtSearch.Text)),

 

ddSearchBy.Selected.Value = "Student ID" And ddFilter.Selected.Result = "All",
Filter('ARST Check Manager',StartsWith(Vendor,txtSearch.Text)),

 

ddSearchBy.Selected.Value = "Last Name" And ddFilter.Selected.Result = "All",
Filter('ARST Check Manager',StartsWith('Last Name',txtSearch.Text)),

 

ddSearchBy.Selected.Value = "Check Number" And ddFilter.Selected.Result <> "All" And optFilter.Selected.Value = "Status",
Sort(Filter('ARST Check Manager',Action.Value = ddFilter.Selected.Result And StartsWith('Check Number',txtSearch.Text)),'Action Date',Descending),

 

ddSearchBy.Selected.Value = "Student ID" And ddFilter.Selected.Result <> "All" And optFilter.Selected.Value = "Status",
Filter('ARST Check Manager',Action.Value = ddFilter.Selected.Result And StartsWith(Vendor,txtSearch.Text)),

 

ddSearchBy.Selected.Value = "Last Name" And ddFilter.Selected.Result <> "All" And optFilter.Selected.Value = "Status",
Filter('ARST Check Manager',Action.Value = ddFilter.Selected.Result And StartsWith('Last Name',txtSearch.Text)),

 

ddSearchBy.Selected.Value = "Check Number" And ddFilter.Selected.Result <> "All" And optFilter.Selected.Value = "Term",
Filter('ARST Check Manager',Term = ddFilter.Selected.Result And StartsWith('Check Number',txtSearch.Text)),

 

ddSearchBy.Selected.Value = "Student ID" And ddFilter.Selected.Result <> "All" And optFilter.Selected.Value = "Term",
Filter('ARST Check Manager',Term = ddFilter.Selected.Result And StartsWith(Vendor,txtSearch.Text)),

 

ddSearchBy.Selected.Value = "Last Name" And ddFilter.Selected.Result <> "All" And optFilter.Selected.Value = "Term",
Filter('ARST Check Manager',Term = ddFilter.Selected.Result And StartsWith('Last Name',txtSearch.Text)),

 

ddSearchBy.Selected.Value = "Check Number" And ddFilter.Selected.Result <> "All" And optFilter.Selected.Value = "Type",
Filter('ARST Check Manager','AR Type'= ddFilter.Selected.Result And StartsWith('Check Number',txtSearch.Text)),

 

ddSearchBy.Selected.Value = "Student ID" And ddFilter.Selected.Result <> "All" And optFilter.Selected.Value = "Type",
Filter('ARST Check Manager','AR Type' = ddFilter.Selected.Result And StartsWith(Vendor,txtSearch.Text)),

 

ddSearchBy.Selected.Value = "Last Name" And ddFilter.Selected.Result <> "All" And optFilter.Selected.Value = "Type",
Filter('ARST Check Manager','AR Type' = ddFilter.Selected.Result And StartsWith('Last Name',txtSearch.Text)),

 

'ARST Check Manager')

1 ACCEPTED SOLUTION

Accepted Solutions
v-xiaochen-msft
Community Support
Community Support

Hi @BarnBrat ,

 

The error message is because you used the behavior function on the wrong control property.

ClearCollect() funcion is a behavior function. It can only be triggered after a event is executed.

For example: When you click on a button and trigger an event, the clearcollect function will be executed.

So you could use ClearCollect() function on the Onselect property of button control.

In addition, there are many such properties, e.g. Onchange , OnVisible,... 

 

Best Regards,

Wearsky

View solution in original post

4 REPLIES 4
gabibalaban
Dual Super User
Dual Super User

@BarnBrat ,

Actually if you use the formula in Items property of the Gallery, the results of the formula can be use as a collection with  galARSTRecords.AllItems.

Hope it helps !

I hear what you are saying, and that is what I want to do, but it's the how that I cannot figure out...

I think I am catching on. After I figure out how to initially load all of the records into the collection, I'll post what I've done 🙂

v-xiaochen-msft
Community Support
Community Support

Hi @BarnBrat ,

 

The error message is because you used the behavior function on the wrong control property.

ClearCollect() funcion is a behavior function. It can only be triggered after a event is executed.

For example: When you click on a button and trigger an event, the clearcollect function will be executed.

So you could use ClearCollect() function on the Onselect property of button control.

In addition, there are many such properties, e.g. Onchange , OnVisible,... 

 

Best Regards,

Wearsky

Helpful resources

Announcements
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.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (1,608)