Get certified for free when you join Fabric Data Days 2026 and dive into Fabric, Power BI, SQL, AI, and other essential data skills.
Join nowData Days is here! Join us now for 60+ days of learning, challenges, and connection. 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
Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.
Check out the May 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 1 |
| User | Count |
|---|---|
| 11 | |
| 11 | |
| 5 | |
| 4 | |
| 3 |