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 / Can I create a collect...
Power Apps
Answered

Can I create a collection based on a global variable?

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I have multiple, identical SharePoint lists and I'd like to load a particular list on all screens based on a global variable called varProject.  I'd like to be able to set all forms and galleries to have a data source of colClaimsList, and then switch out the records they display based on a global variable selection set with a button click on the home page of the app.

 

With the global variable is set, I hoped to create a collection (using ClearCollect) based on the varProject value.

The variable is getting set correctly, but I can't seem to get the collection created. I'm doing stuff like this:

 

If(
 varProject = "Project1",
 ClearCollect(
 colClaimsList,
 'Claims-Project1'
 );
 If(
 varProject = "Project2",
 ClearCollect(
 colClaimsList,
 'Claims-Project2'
 )
 )
);
Navigate(SELECT)

 


Is this not possible? Powerapps seems perfectly happy with the syntax but the collection is not being created/populated. It's always empty. Thanks in advance for your help.

Categories:
I have the same question (0)
  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Anonymous 

    You will only be able to do this successfully if the two sources are the same.  Otherwise you will start to introduce issues into your app.

    Your formula can be set to the following:

    ClearCollect(
     colClaimsList,
     Switch(varProject, "Project1", 'Claims-Project1', "Project2", 'Claims-Project2')
    )

    Again note, that these should be pretty much identical.

     

    I hope this is helpful for you.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @RandyHayes Thanks so much! I was experimenting with Switch functions but I didn't have it quite right. This is working for me now. 

    ClearCollect(
     colClaimsList,
     Switch(
     varProject,
     "Project1",
     "Claims-Project1',
     "Project2",
     'Claims-Project2',
     "Project3",
     'Claims-Project3'
     )
    );

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 June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 296 Most Valuable Professional

#2
11manish Profile Picture

11manish 224

#3
Valantis Profile Picture

Valantis 181

Last 30 days Overall leaderboard