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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Apps
Unanswered

Dynamic table name

(0) ShareShare
ReportReport
Posted on by

Hello,


I have an application where there are many controls changing/creating records in different SQL tables.
In each of these controls the table specific datasource is named, "Company$G_L Entry" etc. 
I would like to have the possiblity of swiftly changing the datasources so that they can point to a different company, "Company2$G_L Entry"

I was hoping that this could be made either by changing the names of the datasources in powerapps or by assigning the different tables to variables. Neither of these two thought seem to be possible so if there is anyone that knows any way of accompishing this I would be very happy! 


Br,
Johannes

Categories:
I have the same question (0)
  • mdevaney Profile Picture
    29,989 Moderator on at

    @Anonymous 

    Did you try using a Switch case to select the table?

     

    Switch(
     myVariable,
     1, 'Company$G_L Entry'
     2, 'Company$H_M Entry'
     3, 'Company$I_N Entry'
    )

     

    ---
    Please click "Accept as Solution" if my response helped to solve your issue so that others may find it more quickly. If your thought the post was helpful please give it a "Thumbs Up."

  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    Hey @Anonymous 

     

    Directly referencing is not possible as the Patch function required a valid data source. As a workaround to this, you can use an If condition as:
     
    Variable to select DataSource: Set(SelectedDataSource,"Company$G_L Entry")
     
    Patch(If(SelectedDataSource= "Company$G_L Entry",'Company$G_L Entry',SelectedDataSource = "Company2$G_L Entry",'Company2$G_L Entry'),Defaults(If(SelectedDataSource= "Company$G_L Entry",'Company$G_L Entry',SelectedDataSource = "Company2$G_L Entry",'Company2$G_L Entry')),{Title:"VarTest"})
     
    Note: Make sure that the columns should be name for the data sources to work properly.
    If this differs, please share more details about the schema of the datasources, so that we might be able to help you better.
     
    Hope this Helps!
     
    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
  • Community Power Platform Member Profile Picture
    on at

    Hello @yashag2255 ,

    I work only with navision which means that when you query table the only difference is the initial company name in the query name.
    "Company$G_L Entry"
    "Company2$G_L Entry"
    etc

    The reason that i'm looking for this functionality is that if we want to apply this application to a subsidiary or to a customer it would be extremly efficient if one could simple replace the source tables with the mirrored one from the new company.


    Summarized I want to know if there is any way to avoid inventing the wheel again if I want to create the same application to a new company!

    @mdevaney ,
    If i put a table into a variable im not able to reference it. I dont know if I'm doing anything wrong?

  • mdevaney Profile Picture
    29,989 Moderator on at

    @Anonymous 

    My code was not intended to store a table inside of a variable.  Instead my goal was just to reference it.  The code actually functions similar to this code segment provided by @yashag2255 

     

    If(SelectedDataSource= "Company$G_L Entry",'Company$G_L Entry',
    SelectedDataSource = "Company2$G_L Entry",'Company2$G_L Entry'
    )

     

    Rewritten as a SWITCH function it would be

     

    Switch(
     SelectedDataSource,
     "Company$G_L Entry",'Company$G_L Entry',
     "Company2$G_L Entry",'Company2$G_L Entry'
    )

     

  • Community Power Platform Member Profile Picture
    on at

    I'm sorry, reading through my previous messages it's not totally clear what i'm actually looking for.

    I don't currently know which additional companies that I will look to apply this application to.
    It might be 10, 15 or 20 different companies and it might be five this year and five in three years. 

    This is the reason why it will not work for me to reference all potential companies in each patch statement. 

    What i'm wondering about is if it's at all possible to change the original source of a query without having to change all the patch statements? Can you somehow make the patch statement reference something that's not a direct path to that specific table? 

    As an example, 
    If you could change the reference name of the table from "Company$G_L Entry" to "G_L Entry" you could then reference the patch statement to "G_L Entry".

    This would mean that you could change the original source while still keeping the reference of the patch statement. 


    Again im sorry for the confusion, it's not always so easy explaining what you're thinking! 🙂

    Br,
    Johannes

  • mdevaney Profile Picture
    29,989 Moderator on at

    @Anonymous 

    Yes, I agree.  Explaining issues over the internet is difficult.  Reading between the lines and trying to give a solution when you not in the same room is hard too... its all part of the joy of problem solving on the forum, hahaha!

     

    Thinking about the future is a very good idea and having to change each PATCH function would be annoying.  Unfortunately, I don't know how to indirectly reference a SQL table by storing in a variable.  Hopefully @yashag2255  will be able to set you on the right path!

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard