cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anna0326
Level: Powered On

How to filter data based on a collection in powerapps?

Hi, 

 

I am fairly new to PowerApps and building a Questionnaire App (includes 6-9 different scenarios) for my team where I source data from multiple SharePoint lists. I have a text box - StoreID which may contain 1 or more values separated by a delimiter ",". I need to filter a gallery of Interface IDs based of the StoreID populated. I am able to do it for single StoreID but I am stuck for Multiple storeIDs. 

 

Here is what I have so far:

For Single StoreID : 

Filter(CustomerList, Customer_ID = StoreID .Text) 

This formula works for 1 StoreID. 

 

For Multiple Store ID: 

1. First, created a collection to store multiple Store IDs when populated

ClearCollect(MultipleShopID,Split(StoreID .Text,","));

2. Second, below is the formula on the Gallery to display/filter Interface IDs for those multiple StoreID .

Filter(CustomerList, Customer_ID = MultipleShopID.Result)

 

FYI, StoreID and Customer_IDs are sourced from 2 different SharePoint list.

However, I am getting delegation error on the second formula.

"Delegation warning the filter part of this formula might not work correctly on large data sets."

 

@yashag2255 ,  @RandyHayes, @Pstork1 , @tpatel  or anyone at the earliest.

Any help is appreciated.

 

Thank you,

Anna

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: How to filter data based on a collection in powerapps?

@Anna0326 

So, you have a couple of choices:

1) If you have to be able to filter on over 2000 records, and you CANNOT delegate a query, then you will need to pull the entire list into a local collection and use that.

2) Or, the approach that you have would work if there was a finite number of Customer ID's allowed to be entered.  For your example, you have two.  If two is all that is allowed, then you could take that approach to make it happen.  but, if that number is flexible and not always 2, then you start to run into problems.

3) Other option is to build another collection based on the Split formula that I gave earlier - 

ForAll(Split(Substitute(StoreID.Text, " ", ""), ","),
    Collect(anotherCollection, Lookup(CustomerList, Customer_ID = Result))
  )

This would have only the customers specified.  This does change your design perhaps, but would also work.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

13 REPLIES 13
jhall
Level 8

Re: How to filter data based on a collection in powerapps?

I'd guess that the "In" operator is what you're after.  You want to include any record if the value in a particular field (e.g. Customer_ID) exists within a particular list (e.g. MultipleShopID).

Customer_ID In MultipleShopID would return a Boolean that could be used in a variety of ways.

Super User
Super User

Re: How to filter data based on a collection in powerapps?

@Anna0326 

You can consider replacing the formula on your Gallery to be the following:

Filter(CustomerList, Customer_ID in Split(Substitute(StoreID.Text, " ", ""), ","))

A couple things here...

1) this will still have a delegation warning - do you have a delegation concern (i.e. do you expect your CustomerList to be over 2000)?

2) You can skip the collection for the split and just do it all in the gallery formula.

3) You will also, most likely, need to pull out extra spaces that people will put between a comma and the next StoreID. This formula has a substitute that will remove those.

 

Give that a try and see where you are.

I hope that it is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Anna0326
Level: Powered On

Re: How to filter data based on a collection in powerapps?

@RandyHayesthank you for your response. 

 

I tried the formula/approach you shared but its only returning the first record under customerID from the list. 

Also, I am getting the delegation error and to your question -yes, there are upto 5000 records (coming from a Sharepoint with that limit).

Can this be fixed?

 

If not, I was wondering about another approach. May be not ideal but a good make do option. 

Split and load each storeID into separate textboxes and then use the filter function for each textbox value.

I tried this approach but I could separate on left and right values but not the mid. 

any idea how I can do this and remove the delimiter in the results?

textbx1= Left(StoreID.Text,Find(",",StoreID.Text))

textbx2= Right(StoreID.Text,Find(",",StoreID.Text))

Filter(CustomerList, (Customer_ID=textbx1.text), (Customer_ID=textbx2.text))

 

thanks,

Anna

Dual Super User
Dual Super User

Re: How to filter data based on a collection in powerapps?

Hi @Anna0326 

 

For filtering the gallery based on multiple values in the text box for Store ID, please try out the below formula:
 
Filter(CustomerList, If(IsBlank(StoreID.Text),true,Customer_ID in Split(StoreID.Text,",")))
 
Also, regarding the delegation part you can try to increase the data row limit for non-delegable queries by following below steps:
 
File -> App Settings -> Advanced Settings -> Data Row Limit for Non-Delegable Queried -> Please update this to 2000 (This is the max limit that can be set by the user). This will remove the delegation warning.
 
Incase, you have more than 2000 records, you might want to store them in a local collection and then retrieve the values from local collection in the app.
 
Hope this Helps!
 
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
Super User
Super User

Re: How to filter data based on a collection in powerapps?

@Anna0326 

So, you have a couple of choices:

1) If you have to be able to filter on over 2000 records, and you CANNOT delegate a query, then you will need to pull the entire list into a local collection and use that.

2) Or, the approach that you have would work if there was a finite number of Customer ID's allowed to be entered.  For your example, you have two.  If two is all that is allowed, then you could take that approach to make it happen.  but, if that number is flexible and not always 2, then you start to run into problems.

3) Other option is to build another collection based on the Split formula that I gave earlier - 

ForAll(Split(Substitute(StoreID.Text, " ", ""), ","),
    Collect(anotherCollection, Lookup(CustomerList, Customer_ID = Result))
  )

This would have only the customers specified.  This does change your design perhaps, but would also work.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

Anna0326
Level: Powered On

Re: How to filter data based on a collection in powerapps?

Thanks @RandyHayes and @yashag2255 

 

Like you both suggested I am trying to use collect function since even after extending the delegation I am not getting all the customerIDs in my gallery. 

 

I used Randy's formula: 

ForAll(Split(Substitute(StoreID.Text, " ", ""), ","),
    Collect(anotherCollection, Lookup(CustomerList, Customer_ID = Result)))

I am gettign an error here- "Behavior function in a non behavior property, you can't use this property to change values elsewhere in the app"

I am not sure what this is referring to... 

Dual Super User
Dual Super User

Re: How to filter data based on a collection in powerapps?

Hi @Anna0326 

 

Can you please confirm the name of property where are you putting this formula in your app?
 
As a suggestion, you can collect this collection either on the "OnChange" property of your text input or can add a button, for button you need to update "OnSelect" property.
 
Also, use the below expression, so that whenever the input is changed, it clears the existing collection and updates it with new values.
Expression: Clear(MyGalleryCollection);ForAll(Split(StoreID.Text,",")),Collect(MyGalleryCollection, Filter(CustomerList, Customer_ID = Result)))
 
This will also fetch multiple records satisfying the condition if there exists any.
 
Hope this Helps!
Community Support Team
Community Support Team

Re: How to filter data based on a collection in powerapps?

HI @Anna0326 ,

Do you want to filter your Gallery Items based on the multiple storeIDs within the storeID Text Box?

 

Based on the second formula that you provided, I think there is some syntax error with it. The MultipleShopID.Result formula would return a Table value, the Customer_ID column is a Text value, you could not compare a Text value with a Table value within the Filter function using "=" operator.

 

Based on the needs that you mentioned, I think the 'in' operator could achieve your needs. Please consider modify your formula as below:

Set the Items proeprty of the Gallery to following formula:

Filter(CustomerList, Customer_ID in Split(StoreID.Text, ",").Result)

Or

Filter(CustomerList, Customer_ID in Trim(Split(StoreID.Text, ",").Result))

 

Above formula may cause a Delegation warning issue, if the amount of your SP List records is not more than 2000, you could ignore this issue (set the "Data row limit for Non-delegable queries" option to 2000 (maximum value) within Advanced settings of App settings of your app).

If the amount of your SP List records is more than 2000, please check and see if the alternative solution mentioned within the following thread would help in your scenario:

https://powerusers.microsoft.com/t5/General-Discussion/Pulling-in-large-ish-SQL-tables/m-p/243777#M7...

On your side, please take a try with the following workaround:

Set the OnStart property of the App control to following (I assume that there are 10000 records stored in your CustomerList😞

Concurrent(
          ClearCollect(col1, Filter(CustomerList, ID >= 1 && ID <= 2000)),
          ClearCollect(col2, Filter(CustomerList, ID >= 2001 && ID <= 4000)),
          ClearCollect(col3, Filter(CustomerList, ID >= 4001 && ID <= 6000)),
          ClearCollect(col4, Filter(CustomerList, ID >= 6001 && ID <= 8000)),
          ClearCollect(col5, Filter(CustomerList, ID >= 8001 && ID <= 10000))
);
ClearCollect(MergedCollection, col1, col2, col3, col4, col5)

Then set the Items property of your Gallery to following:

Filter(MergedCollection, Customer_ID in Split(StoreID.Text, ",").Result)

Or

Filter(MergedCollection, Customer_ID in Trim(Split(StoreID.Text, ",").Result))

Then re-load your app, check if the issue is solved.

Note: Please make sure that you have set the "Data row limit for Non-delegable queries" option to 2000 (maximum value) within Advanced settings of App settings of your app already.

 

Please consider take a try with above solution, then 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.
Super User
Super User

Re: How to filter data based on a collection in powerapps?

@Anna0326 

You will want to put that formula in an OnStart, OnChange or some On... action, of a control that has actions.  You cannot use it in an Item property or other place like that.  Sorry if I failed to mention that.

 

Once you have this in the appropriate place it should solve the delegation issue and then your other operations should work as expected.

For what you are doing I don't see that building a local collection is necessary as you will be able to delegate the Lookup.  

Also, the formula accounts for spaces in the input, which will be needed.

One final question - is the Customer_ID a text or number column?

 

Let's see how that goes for you.  Post any issues you run into.

 

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

Helpful resources

Announcements
thirdimage

Coming Soon: T-Shirt Design Contest

Keep your eyes open for our upcoming T-shirt design contest!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

Top Solution Authors
Top Kudoed Authors
Users online (5,767)