Forum Discussion
Change pbix data source programmatically
- Anonymous9 years ago
Hi JorgeDiego,
As you said, power bi not support to direct modified the datasource without open the pbix file, perhaps you can submit your requirement to ideas.
In addition, you can try to store your connection string to a config file, then write a custom function to analysis this file. After these steps, you can change the datasource without open the pbix file.(After you modified the config file, you should refresh it at pbix report to get the newest data)Sample:
let xmlTable = Xml.Tables(File.Contents("C:\Users\xxxxx\Desktop\test.xml")), server=xmlTable[Server]{0}, database=xmlTable[Database]{0}, Source= Sql.Database(server,database) in SourceXml:
<config> <Server>"abc"</Server> <Database>"edd"</Database> </config>
Screenshots:
Regards,
Xiaoxin Sheng
Hi JorgeDiego,
As you said, power bi not support to direct modified the datasource without open the pbix file, perhaps you can submit your requirement to ideas.
In addition, you can try to store your connection string to a config file, then write a custom function to analysis this file. After these steps, you can change the datasource without open the pbix file.(After you modified the config file, you should refresh it at pbix report to get the newest data)
Sample:
let
xmlTable = Xml.Tables(File.Contents("C:\Users\xxxxx\Desktop\test.xml")),
server=xmlTable[Server]{0},
database=xmlTable[Database]{0},
Source= Sql.Database(server,database)
in
Source
Xml:
<config> <Server>"abc"</Server> <Database>"edd"</Database> </config>
Screenshots:
Regards,
Xiaoxin Sheng
- JorgeDiego9 years ago
Advocate I
It could be a good solution. It is not the best, but, currently, the solution I´m looking for doesn´t exist.
Many thanks.
- Sowjanya18 years agoFrequent Visitor
Could you please elaborate the last part
Source= //invoke data connection method here
Bare with me please, bcoz i'm very new to this.
- kkalyanthaya8 years ago
Microsoft Employee
Anonymous,
Can this method be used as a way to share templates / content packs to connect to different sources ?
The history behind this question is here.
- modelmike8 years agoFrequent Visitor
I was able to solve this problem using a paremeter in Power Query. The parameter is set to the users dropbox "home" local folder. Then, when I share the PBT file it prompts the user to enter their specific filepath before creating their user-specific pbix. This isn't quite automagical but it does the job.
- Liubov_Lehlai2 years agoNew Member
Do you know solution for Direct Query ? As i have Error "2 datasource is not allowed"