Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi,
I was wondering whether it's possible to reuse power query M code in multiple databases if they have the same or similar data structure?
Currently I have a Power BI project which contains a dataset generated from a SQL server database. I used power query editor to construct the data model and it seems to work fine. the various visualizations work fine. I have to create another Power BI project which queries a different SQL server database, but they have the same tables and structure as the original. I want to check whether there's an easy way to reuse the logic in the first project and apply it to the second, rather than copying and pasting the code.
Jason
Solved! Go to Solution.
Hi @Anonymous ,
We can user parameter to work on it. Please refer to the case as below.
https://community.powerbi.com/t5/Desktop/Changing-Data-Source/td-p/497753
Hello @Anonymous
you can create a function out of your query, and using parameters with the database as input... something like that:
(yourdatabase) =>
let
Source = Sql.Database(yourdatabase........
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
Hi all,
thanks for your help. Adding the parameters appear to do the trick.
Sincerely,
Jason
Hello @Anonymous
you can create a function out of your query, and using parameters with the database as input... something like that:
(yourdatabase) =>
let
Source = Sql.Database(yourdatabase........
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
Hi @Anonymous ,
We can user parameter to work on it. Please refer to the case as below.
https://community.powerbi.com/t5/Desktop/Changing-Data-Source/td-p/497753
Dataflows
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 19 | |
| 9 | |
| 8 | |
| 7 | |
| 6 |