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 / Set a flexible datasou...
Power Apps
Suggested Answer

Set a flexible datasource to swtich between multiple sharepoint lists

(0) ShareShare
ReportReport
Posted on by 3
Hi all,
 
another delegation questions. Thanks already for the help.
 
I've set up my app to dynamically switch the datasource (I'm using 7 different sharepoint lists). 
I do this as I use individual access rights per sharepoint list row (with power automate) - here Microsoft recommends a maximum of 10k rows which I would soon reach if I wouldn't use the dynamic data source selection.
 
To get the dynamic selection, in my App onstart I'm selecting the correct sharepoint list based on the current user and save it as CurrentListSource.
 
This I'm then using for my gallery. It works but with delegation issues and can therefore only see the first 2000 items. Is there any way to stay flexible with the sources but avoid these delegation errors?

I'm using this App onstart:
  • Set(AppLanguage, "en");
    ClearCollect(colPlants, Plant_Mapping);
     
     
    // --- 2. Dynamic List Selection Logic ---
     
    // Create the Claims token for the current user once
    Set(CurrentUserClaims, "i:0#.f|membership|" & Lower(User().Email));
     
    // Look up the current user's configuration record using the Claims token
    Set(
        CurrentUserConfig,
        LookUp(
            Users_SharepointList,
            // Compare the INDEXED TEXT column to the current user's email (Text = Text)
            UID = User().Email
        )
    );
     
    // --- 3. Set Global Variables ---
    Set(
        CurrentListName,
        CurrentUserConfig.'Sharepoint List'
    );
     
    Set(
        CurrentListSource,
        Switch(
            CurrentListName,
            "List1", 'List1',
            "List2", 'List2',
            "List3", 'List3',
            "List4", 'List4',
            "List5", 'List5'
        )
    );
     
     
And this gallery items formula:
  • CurrentListSource
 
If directly reference a specific sharepoint list the error doesn't come up. So the issue must relate to the CurrentListSource. 
 
Would be thankful for any suggestions on why this doesn't work. 
I have the same question (0)
  • Suggested answer
    WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    I will save you some time here - dynamic data source references simply do not work for a number of reasons  - including Power Apps needs to validate any potential query at the time you write it and also any potential output always needs to be valid - it does not know what you are going to set the variable to in the future.
     
    If your lists are under 2,000 records (and are identical in file names and types), you can do this
    ClearCollect(
       colMyData,
       Switch(
          CurrentListName,
          "List1", 'List1',
          "List2", 'List2',
          "List3", 'List3',
          "List4", 'List4',
          "List5", 'List5'
       )
    )
    and then filter the collection.
     
    Otherwise, have 5 galleries with identical filters on each list and make the appropriate one visible based on the Variable value, You would then set identical variables OnSelect and go from there.
     
    Please ✅ Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like ♥
    Visit my blog
    Practical Power Apps    LinkedIn  
     
     
     
     
  • CU11021352-0 Profile Picture
    3 on at
    Thanks for the reply @WarrenBelz! I appreciate it a lot.
    I guessed the same, but this will save me some time with further tests. I've been trying loads of different versions to get this to work. 
     
    Do you know if creating multiple galleries will result in performance issues if I just hide them? 
    Do Forms connected to the gallery then also need to be created multiple times? Or would it work to flexibly select the correct gallery within one form?
     
    thanks again
  • WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    As for performance, it should not affect you to any visible extent with only five of them, however you have the same issue with a Form as they need to be bound to a Data Source as well. 
     
    However there may be a workaround for this as you can set a Variable for the OnSelect of the Gallery either
    Set(
       varList,
       {
          Record: ThisItem
          List: "List1"
       }
    )
    Then you are going to need individual controls (you can put them in a Form to make it neater it you want, but in New mode) with the Default of each control (using your field names)
    varList.Record.YourFieldName
    and then conditionally patch the appropriate list based on the value of varList.List 
     
    or have five forms the same as the galleries.
     
    Personally I would go for the second one - totally reliable, future-proof and far less complex.
     
    Please ✅ Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like ♥
    Visit my blog
    Practical Power Apps    LinkedIn  
     
  • WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    A quick follow-up to see if you received the answer you were looking for. Happy to assist further if not.
     
    Please ✅ Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like â™¥
    Visit my blog
    Practical Power Apps    LinkedIn   

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 424

#2
WarrenBelz Profile Picture

WarrenBelz 355 Most Valuable Professional

#3
11manish Profile Picture

11manish 290

Last 30 days Overall leaderboard