Delegation of queries in Canvas Apps/Custom Pages has long been a troublesome topic and we are always looking out for the triangle of doom, or the double blue underline of eternal stench (well, it is Halloween soon!)
I try to keep a close eye on the connector delegation support table in the official documentation for any changes and additions. Part of what I love about the Power Platform is that new features are constantly being released, often without fanfare!
Here is the current delegation support at the time of writing (for posterity from the docs):
|Item||Number ||Text ||Choice||DateTime ||Guid|
|<, <=, >, >=||Yes||Yes||No||Yes||–|
|In (membership) (preview)||Yes||Yes||Yes||Yes||Yes|
|IsBlank||Yes ||Yes ||No ||Yes ||Yes|
|Sum, Min, Max, Avg ||Yes||–||–||No||–|
|CountRows  , CountIf ||Yes||Yes||Yes||Yes||Yes|
The Caveats are important – especially around aggregation limits:
- Numeric with arithmetic expressions (for example,
Filter(table, field + 10 > 100)) aren’t delegable. Language and TimeZone aren’t delegable.
- Doesn’t support Trim[Ends] or Len. Does support other functions such as Left, Mid, Right, Upper, Lower, Replace, Substitute, etc.
- DateTime is delegable except for DateTime functions Now() and Today().
- Supports comparisons. For example,
Filter(TableName, MyCol = Blank()).
- The aggregate functions are limited to a collection of 50,000 rows. If needed, use the Filter function to select 50,000
- CountRows on Dataverse uses a cached value. For non-cached values where the record count is expected to be under 50,000 records, use
- For CountRows, ensure that users have appropriate permissions to get totals for the table.
Old ‘in’ delegation limit
The really exciting addition to this table is the mention of ‘In (membership)’. It is currently marked as preview but can be used in the latest version of canvas studio.
Previously, if you had written a formula to get all the accounts that had a primary contact of A or B it might look like:
Set(varInFilter, [ First(Contacts).Contact, Last(Contacts).Contact ]); ClearCollect(colAccounts, Filter(Accounts, 'Primary Contact'.Contact in varInFilter) );
In this situation, previously you would have been presented with the delegation warnings:
When you execute the query you would have seen the warning:
The reason being is that the query that was executed against Dataverse would be:
Here there are no filters that are sent to the server to filter by the primary contact, so the delegation limit will be hit.
The new ‘In’ server-side delegation!
With the new behaviour, if you are using version 3.22102.32 or later (See all versions), the ‘in’ operator is now delegable to Dataverse. This means you will see no warning:
And inside the monitor, you see a clean delegated query!
This is because the filtering is now performed on the server using the OData query:
/api/data/v9.0/accounts? $filter=(primarycontactid/contactid eq ... or primarycontactid/contactid eq ...)&$select=accountid,primarycontactid,_primarycontactid_value
primarycontactidis filtered using the OR query. This is great news because we no longer will hit that delegation limit.
Those troublesome polymorphic relationships
One of the constant challenges in Power Fx is the support for polymorphic relationships in Dataverse when performing delegated queries. This new support is no exception, unfortunately. If you were to write the following formula you would still hit the delegation limit:
ClearCollect(colcontacts, Filter(Contacts, AsType('Company Name',[@Accounts]).Account in varInFilter) )
I’m going to be keeping an eye out for this to be supported in the future and I’ll let you know!
Check out my video showing this new ‘in’ delegation when used with the Creator Kit!
This blog is part of Power Platform Week.
About the Author
Microsoft Biz Apps MVP, Power Platform. Solution Architect, He/Him/His, Father of the Ribbon Workbench.
Durow, S., 2022, Power Fx delegation of ‘in’ operator against Davaverse, Available at: https://www.develop1.net/public/post/2022/10/24/power-fx-delegation-of-in-operator-against-davaverse [Accessed 10th January 2023]