web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Explicitly declared co...
Power Apps
Answered

Explicitly declared collections as a datasource for a gallery

(0) ShareShare
ReportReport
Posted on by 433

Is it possible to explicitly declare a collection and use it as the data source for a gallery?  When I try, it acts as if I don't have a data source.  I can't add fields and it finds no rows.  In my test app, I'm using the following under the Items property of my gallery:

ClearCollect(CollectionX,{dummyfield:"x"})

 

I think that creating the collection under items creates a temporary collection (which means I shouldn't be creating a collection name that isn't linked to the data source), but I haven't found the syntax that allows me to define the records in such a way that they are recognized as a data source.

 

I'm thinking that perhaps the collection needs to already exist so I can select it for this gallery.  Where would I put it, then?  I already have code in the app's On Start property.  And how could it serve as a data source for the gallery?

 

Categories:
I have the same question (0)
  • mdevaney Profile Picture
    29,991 Moderator on at
    There’s nothing wrong with your code. You just can’t put it directly into Items. Instead, put your code in the OnSelect property for a button

    ClearCollect(CollectionX,{dummyfield:"x"})

    And then put the Collection into the Items property of your gallery

    CollectionX

    The general concept here is that you can only change a collection using a behaviour based property such as OnSelect, OnSuccess, OnVisible, etc. It is not possible to manipulate collections in non behaviour properties such as Items, Default, Text, etc.

    —-
    Please Accept As Solution if this post answered your question so others can find it more quickly. If you found this post helpful consider giving it a Thumbs Up.
  • akharns Profile Picture
    433 on at

    So the user has to push the button to see the info?  There ought to be a way to make it happen without user action.

  • mdevaney Profile Picture
    29,991 Moderator on at
    You can put the code in the OnVisible property of the screen instead.

    ClearCollect(CollectionX,{dummyfield:"x"})

    My example of using the OnSelect property of the button was just for demonstration. The simplest rule to remember is you can use the function ClearCollect() if in any property starting with the word “On”.

    —-
    Please Accept As Solution if this post answered your question so others can find it more quickly. If you found this post helpful consider giving it a Thumbs Up
  • akharns Profile Picture
    433 on at

    Ok, just one more question then:   There aren't very many places to create collections then.  Is there a way to declare more than one collection in one place?  Otherwise, I am severly limited on how many collections I can declare.

  • Verified answer
    mdevaney Profile Picture
    29,991 Moderator on at
    Oh, you can totally declare as many functions as you want in the same property. To do this separate the statements by semi-colons. Try putting this code into the OnVisible property:

    ClearCollect(CollectionX,{dummyfield:"x"});
    ClearCollect(CollectionY,{dummyfield:"y"});
    ClearCollect(CollectionY,{dummyfield:"z"});

    As you can imagine the semi-colon works with all PowerApps functions allowing you to chain together several functions and create more complex apps.

    Hope I answered your question!
  • akharns Profile Picture
    433 on at

    Perfect.   Now I am happy.  Thanks for all your help.

  • mdevaney Profile Picture
    29,991 Moderator on at
    @akharns
    Awesome, have a blast with those new collection techniques!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 379 Most Valuable Professional

#2
11manish Profile Picture

11manish 203 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 128 Super User 2026 Season 2

Last 30 days Overall leaderboard