cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
martinav
Super User
Super User

How to search for multiple known record IDs in a single Lookup() or Filter() Call

Let me explain this a little.  I am trying to make a single, efficient call to a Sharepoint database (>5000 records).  I know a unique single ID to search that willl return one value.  I have a list of ID to search.  I want do do this in a single call in order to make this a quick and efficient call.  It would be like stringing 'or' statements together in a filter.  That would capture the essense of what I want to do.  I'm avoiding ForALL() because that would make a call for every single item in the criteria array.

 

My example:  I think this shows what I'm wanting to do, even though this is not a workable syntax, etc.

 

ClearCollect(ResultingTable, With({ListIDs: [123, 423, 163,133]}, Filter(SPList, ListIDs in SPList.ID)))

 

 

8 REPLIES 8
RandyHayes
Super User
Super User

@martinav 

Unlike some other functions (like Remove) where you can provide a table of ID's, there is no function in PowerApps where you can provide a table of ID's and have only those returned.  

 

Your Option would be to utilize the ForAll to return a table of all the records based on the ID's

With({ListIDs: [123, 423, 163, 133]}, 
    ForAll(ListIDs,
        LookUp(SPList, ID=Value)
    )
)

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
martinav
Super User
Super User

@RandyHayes ,

 

Yea, that works, but breaks my premise.  Its expensive to make separate calls with a ForAll().  Especially as the table if ListIDs gets larger.  I think I will attempt to get a grab of the lastest 100 or 200 rows of data, then do the forall() statement to the resulting filtered collection.

RandyHayes
Super User
Super User

@martinav 

Yes, it is expensive to call any datasource functions in a ForAll (which is another reason it should be used as a function to create a table and not as a ForLoop!)

However in this case, the goal is to mimic the Filter function with specific ID's.  So, the formula I provided would do just that...a table of records just like any other filter statement, but only for those ID's.  And...at a cost!

 

I'm not sure that you would gain any performance changes by gathering 100 or 200 rows of data and then a ForAll over them as you will now incur the cost of gathering the 100 or 200 rows of data.

I would test that against the data first.

 

My assumption is that the ID list will change dynamically, but if it didn't then the ID's could be incorporated into a filter statement...but that is not the case here as I assume.

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
martinav
Super User
Super User

@RandyHayes  or anyone!!

 

Is there any new creative methods to handle this?  

dipique
Frequent Visitor

Yes, but not without caveats. Given a collection of records ("recordCollection") that have a foreign key ("Fk"), you can fetch all those foreign keys from their table like this:

 

Filter('Table To Query', ID exactin recordCollection.Fk)

 

The caveat is that this will trigger a delegation warning, so the normal large dataset issues apply.

dipique
Frequent Visitor


@dipique wrote:

you can fetch all those foreign keys from their table like this


That is, all the records associated with those foreign keys.

@dipique ,

 

Unfortunately, that caveat does make the method unusable for this case.  Delegation is often the dissenting factor for many methods.

dipique
Frequent Visitor

I see now that you even specified the record count in your question. Sorry about that.

 

I’m guessing your best bet is capitalizing on some common attribute of the items in that list that gives the ability to sort. I actually came to this page for the same problem as you and came up empty.

 

Another idea I’ve yet to try is running each single-record call as soon as I know it will be needed. In my case, users are making selections of items to include and I am fetching the associated records. I’d like to fetch them all when they “submit”, but if performance is my concern, I could also do background fetches as each selection is made. By the time of submission the data would already be in a collection.

 

I hope you find some creative solution to the issue. Seems like a silly gap in capability for power apps. That said, SharePoint lists have always been problematic when dealing with large numbers of records, even before the power apps days. If you have access to dataverse, it would likely make your life a lot easier. 

Helpful resources

Announcements
October Events

Mark Your Calendars

So many events that are happening this month - don't miss out!

Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

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