Introduction
Read this carefully to understand, again and again, until you understand. This is the easiest explanation with use cases/scenarios of the formula I could have provided.
We are delegating the execution of filtering and searching for records to the data source. This indicates that the entire query will run on a data source's side rather than burdening Power Apps directly. Stated differently, the desired data will have already undergone filtering on the side of a data source, and the outcome will be sent to Power Apps. Thus, once everything is finished, the Power Apps side only needs to receive the desired data.
Scenario
In this article, we will see how we can replace delegable function issues with nondelegable functions.
StartsWith can replace the search function which has delegable issues. IsBlank() can be replaced by Blank() function.
Objective
It is important to know what is delegable and what is not. In the formula when we write, we get the warning (yellow triangle) which says that our formula is not delegable.
In Power Apps Canvas Apps only certain functions are delegable. If we use just one nondelegable function in our query, then the whole query won't be delegable. So, it is very important that we compose our query by carefully choosing delegable functions.
Delegable data sources
Delegable datasources are,
- SharePoint
- Microsoft Dataverse
- SQL Server
- Salesforce
The above datasources are delegable. In case we work with the above datasources, we might need to face delegation. As we know, Excel workbooks, collections, and tables are stored in Power Apps Canvas App, so for searching and filtering, we can use whatever function we wish to and the application does not require delegation.
Delegable Functions
Delegable functions are,
- And (including &&), Or (including ||), Not (including !)
- In
- =, <>, >=, <=, >, <
- +, –
- TrimEnds
- IsBlank
- StartsWith, EndsWith (these are very important functions, I use them very often)
- Constant values that are the same across all records, such as control properties and global and context variables.
- Sort and SortByColumns
- Sum, Average, Min, and Max (but only a limited number of data sources support this delegation at this time )
Starts With
The function of the chosen field cannot be delegated. The person field is utilized with the StartsWith function. We must understand when these functions can be utilized because the StartsWith function also operates with single-line text fields and number fields. Therefore, it is best to construct, say, a single line of text field adjacent to a choice field and update it in the same way that we would edit a choice field if we want to filter the field. The name of this field would be the [TECHNICAL] field, and its sole purpose would be filtering.
How to analyze if there is a delegation issue in the app?
Mostly there will be a yellow triangle icon that depicts the delegation issue. In certain scenarios, even this delegation icon will not appear, and we have to evaluate the resulting data if it is correct or not.
How to fix delegation?
The way the formula is written has to be structured. For example- Nested if creates a delegation warning. In that case, avoid writing nested if and think of a logic that has only one parent if condition, and all other functions, like filter, start with are inside only one if condition.
We will receive a delegation warning if we use a function that is not yet supported by the data source.
We will see a blue/orange line under some parts of the code, along with a warning triangle.
In form, it is not majorly a problem. However, in a gallery or datatable, it is crucial to fix delegation because the gallery or data table shows all values as per the requirement.
Example of delegation Functions
IsBlank
Filter(‘[@DataSource]’,IsBlank(ColumnName)) gives delegation warning. This could be replaced by
Filter(
‘[@DataSource]’,
ColumnName = Blank()
)
Search
Search(‘[@DataSource]’,”SearchText”,”ColumnName”) gives delegation warning. This could be replaced by
Filter(
‘[@DataSource]’,
StartsWith(ColumnName, “SearchText”)
)
Realtime example
I am using the Filter Function in the PowerApps gallery item.
Suppose Column_3 is a choice column having 4 values as a,b,c,d.
But Column_name3 <> is giving me a delegation warning. So, I can not go for that option.
One of the alternate solutions could be
Filter(
Data_Source,
(Column_name1 = "a") &&
(Column_name2 = "c") &&
((Column_name3 = "a") ||
(Column_name3 = "c") ||
(Column_name3 = "d"))
)
Conclusion
It is important to note that not all data sources can handle expressions that can be stated in a Power Apps formula, though Microsoft Power Fx language is a very powerful tool overall.
This indicates that in order to deal with datasources, delegation is required because, in the event that we attempted to perform our queries on the side of a datasource, they would cease to function properly. Since many of these functions are simply absent, datasources would be unaware of the functions we employ! SQL Server is a part of this as well.
We only utilize common and standard functions in the delegation for our query to execute on the side of a datasource because Power Apps Canvas Apps have implemented an extensive list of functions that are not present in different datasources. The query could not be fully executed on the side of a datasource, If we would use custom Microsoft”s Power Fx functions that only Power Apps has implemented, In this case, the function would be fully executed on the side of the PowerApps Canvas app instead.
In this article, we saw how to analyze delegation and how to overcome them. A few other important functions, like Group, also throw delegation, and we need to look for alternate ways of forming the formula is only the solution.