How to check if a collection is empty in Power Apps canvas apps

Hello everyone and welcome to my blog. In today’s blog, I will show how can you check if a collection is empty in Power Apps.

There are primarily two ways you can check if a collection is empty. The first is using the IsEmpty function. In the below example, the IsEmpty function will initially return false and then true.

ClearCollect(
    collItems,
    {
        Id: 1,
        Name: "Foo"
    },
    {
        Id: 2,
        Name: "bar"
    }
);

IsEmpty(collItems);

Clear(collItems);

IsEmpty(collItems);

There is another way to check if a collection is empty. And that is using the CountRows function. The above code can be rephrased using the CountRows function

CountRows(collItems) > 0

Don’t use IsBlank() to check if the collection is empty or not. The IsBlank() is used to check for null values. IsBlank() can be used to check if a collection is defined or not. It cannot however be used to check if a collection is empty.

Hope this helped.

Debajit Dutta


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

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

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

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

Continue reading