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

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

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.

Top Solution Authors
Users online (2,061)