CountRows function returning zero for DataVerse tables – Power Apps Canvas apps

Hello everyone and welcome to my blog. In today’s blog I will discuss a peculiar behavior with the CountRows function.

Below is an example where I am using the CountRows function to show the total number of customers. Quite strangely, the function returns zero as you can see from the below screenshot.

This is quite unexpected since the documentation state it should return the count of all records in the datasource.

As it turns out, to get the rows we have to specify a column name of the datasource. In the below screenshot I have used the ‘Account‘ column which is basically the accountid (primary key) of the accounts table. You can use any other column of the account table.

And you see the record count is 11.

While it seems to be weird, there is a portion in Microsoft documentation which hints at this behavior.

If you come across this documentation, you may end up with using CountIf and it would give the same result as long as the record count is within the delegation limit.

Remember, CountIf is subjected to delegation limit whereas CountRows without filter is not. Hence it’s better to always use CountRows with column name to get real time count of the rows of DataVerse instead of CountIf.

Hope you liked this post. If this post has helped, you can buy me a coffee.

For similar topics on Microsoft.NET and Power Platform, subscribe to my blog using the Subscribe option on right pane.

Debajit Dutta
Business Solutions MVP


Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe to get the latest posts sent to your email.

1 thought on “CountRows function returning zero for DataVerse tables – Power Apps Canvas apps”

  1. Hi Debajit,
    Thanks for your posting about the CountRows issue.
    The issue occurs in developer environments, because the cache is not updated by design for this type of environment (confirmed by the Product team).

    There exists a support ticket for this case (#2209260050000410) and an idea that can be voted for (https://powerusers.microsoft.com/t5/Power-Apps-Ideas-read-only/Refresh-cache-for-CountRows-in-developer-environments/idi-p/1809333).

    This behavior occurs when the setting Enhanced delegation for Microsoft Dataverse setting is enabled.

Comments are closed.

Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading