Dec 14
PowerApp: CountRows Delegation workaround

I have been working on a PowerApp as of late, where if there is no rows, Change the text to “New”, If there is only 1 Row, Change the text to “Edit” (The app only expects 1 row in this list for this particular app)

In order to accomplish this, one may write: If(CountRows(Filter('SWMS Emergency Response', SWMS.Value=Text(RecordsGallery1_3.Selected.Title))) > 0, "Edit", "New")

However, this produces the usual delegation error, as CountRows is not one of the functions which can be delegated to SQL/SharePoint/etc.


The Solution!

Code: If(Sum(ForAll(Filter('SWMS Emergency Response', SWMS.Value=Text(RecordsGallery1_3.Selected.Title)),1),Value) > 0, "Edit", "New")


The code works by - for any rows found in the conduction, we Add 1, then sum the result - If it it is 0, it is “New”, otherwise it is “Edit” and it delegable.

In essence, the magic piece of code is Sum(ForAll(Filter(‘Datasource’,Filter),1),Value) – It is then just wrapped in an If() condition

This exact feature (CountRows (and SUM)) has been requested to be made delegatable and it does have a status of planned.


Hope this helps!



There are no comments for this post.