In this article, we are going to understand what PowerApps Delegations is, how Delegation works, Delegable data sources, and Delegable functions. We will also go through some examples and understand how to overcome PowerApps delegation issues.
What is Delegation?
- In simple words, To Delegate means assigning tasks to someone else.
What is PowerApps Delegation?
- In PowerApps when you are working with the data sources (CDS, SQL, SharePoint, etc…), the data processing tasks are assigned to data sources rather than done by PowerApps itself. This is called PowerApps Delegations.
- In order to lower the data processing at the PowerApps level, if the data are processed at the data sources level, it will speed up the App, eventually improving the user experience. That’s why PowerApps delegation is so important to understand.
What is PowerApps Delegable Data Sources?
- Delegable data sources mean the data sources that process data logic in a similar or almost similar fashion that PowerApps does.
- Not all the data sources support all the functions of PowerApps.
- There are several data sources that are supported to work with PowerApps, but only a few of them support Delegations from PowerApps.
- Here are the famous and widely used delegable data sources.
- Common Data Service (CDS)
- SQL Server
- SharePoint
What is PowerApps Delegable functions?
- Again, there are a bunch of functions to help us in building the PowerApps application but there are only a few functions that are Delegable.
- It is also dependent on the data source and column type on which the function is being operated.
- While you are creating the PowerApps application, if the function is not Delegable, it will give you a warning sign on the formula like below stating – Delegation warning: The “filter” part of this formula might not work correctly on large data sets.
- If you want to use formula but a function in the formula is not Delegable, then you need to bring the data in PowerApps and then use PowerApps functions on the data.
- You can check the Delegable functions.
What is the limit of Non-Delegable records?
- If the functions can’t be delegated, then the records will be processed locally in the PowerApps and for that, you will have to bring data in PowerApps.
- Now, there is a limit on the number of records you can bring in PowerApps.
- The default limit for Non-Delegable record is 500
- You can extend the default limit to a maximum of 2000 by following instructions.
- Open your app
- Go to File Tab >> App settings
- Click on Advanced Settings.
- You can set the value: Data row limit for non-delegable queries
- Most of the cases, the 2000 record limit can satisfy your requirement. Choose wisely and according to your requirement because when the number of records increases, the load time of the app also increases, and that gives a bad user experience.
- You can check the Non-Delegable functions.
Note:
- The already imported Excel workbook, Collections, tables stored in context variables, don’t need delegations because they are already loaded in the app so the PowerApps can function on that.
PowerApps Delegations Issues Examples and solutions
- Example 1: Filter(Weathers, Now() <= DateAdd(DateDisplayed, 5, Days))
- Issue: In this formula, DateDisplayed is a DateTime column which is not constant. For every row in the Weathers table, this formula would add 5 days in DateDisplayed column value using the DateAdd function and then compare the resulting value with the Now() function. There is clearly a lot of work for the right-hand side of the formula and it will just collapse for a large database.
- Solution: You can initially store the value of DateAdd(DateDisplayed, 5, Days) in a context variable or label and then directly use that value in the formula.
lblDateValue = DateAdd(DateDisplayed, 5, Days)
Filter(Weathers, Now() <= DateValue(lblDateValue.Text))
- Example 2: Filter(Weathers, User().Email = CustomerEmailAddress)
- Issue: In this formula, for each row, logged in user’s email is calculated using User().Email and then it is compared with the CustomerEmailAddress column. This will again cause an issue on a very large database.
- Solution: The solution is very simple in this kind of case. You can put the value of User.Email() in a label and use that label value in the main formula.
lblUserEmailValue = User().Email
Filter(Weathers, lblUserEmailValue.Text = CustomerEmailAddress)
Note: In general practice, to avoid Delegation warnings, keep your complex formula in a variable and use that variable value in your formula.
PowerApps Delegations general workarounds
- The quickest and Not-Recommended fix is to increase the limit of the Non-Delegable records from the app settings as mentioned above in the Non-Delegable records section.
- What you can do is keep the Non-Delegable records limit to 1 only and then use all the possible Delegable functions. This is a kind of POC on what all the Delegable functions you can use in your application.
- Choose your Data Source wisely. If you have more than 5000 records, I would prefer SQL Server or Common Data Service (CDS) because SharePoint has its own limitation of searching in more than 5000 records, in that case, you might need to index the SharePoint column which is being searched from PowerApps.
- You can create some Static views with filters and use those views instead of the table directly
- Let’s take a scenario where you want to display all the records of students having City = Mumbai and Examination Center = 501 and Percentage > 50%
- Now, in this case, if you are working on a large dataset (assume more than 50000 records) and try to filter using above mentioned 3 filters then you are going to face a delegation issue.
- SOLUTION: If you create a Static view specifying City = Mumbai (Let’s say viewMumbaiRecords), then you will be able to lower down the number of records to operate on.
- Now, in this view you only need to apply two filters.