Microsoft Power Apps

Comparing collections, table variables and data sources in Power Apps

In Power Apps you can use data sources directly or you could use collections or you could use variables. But what is the difference?

Performance and behaviour

In my example app I’m reading data from a SharePoint list and display this in three galleries. Within the app startup I’m setting a variable and a collection to the content presented by the connection to my SharePoint list.

The variable and the collection are set using the following two lines of code in my app on start code. The first line is creating a variable using the Set Function and the second line is creating a collection using ClearCollect.

Set(varItems, Connectors);
ClearCollect(colItems, Connectors)

Now as my app loads the 3 galleries, we can see a difference quite quickly. When I count the items in the three galleries I’m finding 100 or 500 items. So that means that the connection loads only the first 100 items in my connection.

Scrolling through data from connections

And as we scroll through the data, we will find that the gallery needs to load the next page of data and the item count is increasing by 100 every time I try to read the last items in the gallery.

The galleries that load the data using the collection or the variable however don’t show this behaviour.

So should we always use collections/variables?

In the above two short videos you can already see that the collections/variable based galleries took a lot longer to load, while the gallery that used the connection directly performed a lot better straight away.

But there are a few more differences.

Collections and variables and CountRows

Before the data has been loaded, the variable behaves in a different way from the collection and the datasource.

You might have noticed earlier that the variable returns 0 on an empty table, while the other two options return a blank value.

The variable of the type table, has been initialized as a table, while the collection has not been initialized until the data has been read.

Collections Overview

Then the final major difference between variables and collections is the way Power Apps is managing them within the UI. If we first look at the collection overview, we can see that the data in the collection is being displayed.

When we compare the collections overview with the variables overview then we can see where the variable is defined (in our case in the App.Onstart) and where it has been used. While we can still see the data in the variable as well.

The above variables overview could sometimes help when you try to debug you app.

Pieter Veenstra

Business Applications and Office Apps & Services Microsoft MVP working as a Microsoft Productivity Principal Consultant at HybrIT Services. You can contact me using

View Comments

  • Hi Pieter, would it be possible to filter datatable using another datatable. Trying to filter CDS table based on lookup table.

    • Yes, you can filter any data table on any data. Do you have any more details on what you are trying to do?

      • I am trying to build canvas app control for Quotes which I can embed on form for the subgrid(lines). There are items in item table but for the account on quote we have contract which contains set of items not complete and each based on the price list. If the price list match then only pull those items and show in Grid(another) for adding in the grid.

        Quote -> Account(lookup)-->Contract(N)--> Contract Items--> Item --> Price List(N)

        so Ideally I am looking for a way to grab all items with associated pricelist on Quote that fulfills Account contract as well. I know we have done it via JS but trying my hands on canvas app to see if this is possible.


Recent Posts

3 steps to implementing a better date picker in Power Apps

One of the biggest annoyances of Canvas Apps in Power apps is the date picker.…

3 days ago

Power Automate Flow run failed: Connection not configured for this service

Today I was battling with the Connection not configured for this service error. Background Iv'e…

3 weeks ago

Open Word documents in the desktop app from Power Apps

When you open Word documents from Power Apps you might have noticed that Word Online…

2 months ago

Introducing Portal Apps in Power Apps

Power Apps has three types of apps. One of them is the Portal app. In…

2 months ago

NEVER give your SharePoint fields the displayname of Value!

After an hour of banging my head against a brick wall when my Patch command…

2 months ago

Collect flow runs of your failed child flows

When you use child flows, you might need to collect the flow runs of your…

2 months ago