Blog
Performance - Why is LookUp better than First/Filter?
Two popular ways to retrieve a single record are to call LookUp, or First(Filter. From a performance perspective, it's better practice to call the LookUp function to return a single record. This to post describes the reason why it's better to call LookUp, compared to First/Filter.
Example scenario
As an example, let's take a system that stores issue records. Against each issue record, users have the ability to mark whether or not an issue is an emergency.
The requirement is to add a form to an app that displays the first record that is marked as an emergency. To accomplish this, we add a display form to a screen, and we set the data source property to the issue table.
To configure the form to display the required record, we set the Item property to a variable, which we set in one of two ways.
We can apply the LookUp function like so:
Set(varRecord,
LookUp('[dbo].[Issue]', IsEmergency=true)
)
Set(varRecord,
First(
Filter('[dbo].[Issue]',
IsEmergency=true
)
)
)
How well does the LookUp pattern perform?
How well does the First(Filter.. pattern perform?
Because Filter function is designed to return multiple records (as opposed to a single record with the LookUp function), Power Apps requests 500 records from the data source. In practice, this value corresponds to the 'data row limit' value in the app settings, which could be up to the maximum of 2,000 records.
Arguably, the impact of using First/Filter would not be so bad if we were retrieving a record by a primary key value. However, LookUp also has the added benefit of being more readable, compared to calling to two nested functions.
Conclusion
- Categories:
- performance
- formula
- data