Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
jrieman
Frequent Visitor

Is it Possible to Parameterize Server Type - Switch From MySQL to SQL Server?

edited for clarity

Is it possible to parameterize  the database type I'm connecting to?  I want to change from MySQL server to SQL Server.

 

My reports query databases hosted on a MySQL server.  My company is transitioning away from MySQL to SQL Server.  We've replicated all server objects found on our MySQL server in  SQL Server (tables, views, sprocs all use same names).  As table, view, and sproc names haven't changed the PBI report queries shouldn't need to change. Some queries are simple select *s against views, some are more complex with joins and such. There aren't any syntax issues or the like (using functions not found in T SQL, etc.) to worry about in my queries.

 

I simply want to point the queries towards a SQL Server datasource with the option of choosing between MySQL and SQL Server.  Then, if I needed to I could switch back and forth between the data hosted on MySQL vs. the data hosted on SQL Server.  

 

Below:  I want to change connection prefix from MySQL.Database to Sql.Database 

jrieman_0-1725558862871.png

 

1 ACCEPTED SOLUTION

I ended up doing it by making Source conditional, based off value of parameter, within the Power Query advanced editor.  

I'm using the approach below.

 

let
    Source =if server= "xerxes" 
    then MySQL.Database("xerxes.corp.brillo.com", "brilloweb_api", [Query="select *#(lf)from products;", ReturnSingleDatabase=true])
    else if 
    server = "alexander"
    then Sql.Database("alexander.corp.brillo.com", "brilloweb_api", [Query="SELECT * FROM products p;"])
    else MySQL.Database("xerxes.corp.brillo.com", "brilloweb_api", [Query="select *#(lf)from products;", ReturnSingleDatabase=true])  
in
    Source

 

jrieman_0-1725656021675.png

 

View solution in original post

8 REPLIES 8
jrieman
Frequent Visitor

Running native queries I write.  Thank you for the links/info. 

 

 

 

Ok here's my proposal:

 

in your Power Query script have both the SQL and the MySQL Sources.  Make the query dynamic so that the "inactive"  connection runs something like "Select top 0 ... ", and the "active"  connection runs your actual query.  Append both queries.

I ended up doing it by making Source conditional, based off value of parameter, within the Power Query advanced editor.  

I'm using the approach below.

 

let
    Source =if server= "xerxes" 
    then MySQL.Database("xerxes.corp.brillo.com", "brilloweb_api", [Query="select *#(lf)from products;", ReturnSingleDatabase=true])
    else if 
    server = "alexander"
    then Sql.Database("alexander.corp.brillo.com", "brilloweb_api", [Query="SELECT * FROM products p;"])
    else MySQL.Database("xerxes.corp.brillo.com", "brilloweb_api", [Query="select *#(lf)from products;", ReturnSingleDatabase=true])  
in
    Source

 

jrieman_0-1725656021675.png

 

Your code is redundant - you could fold the SQL server into the Else branch.

 

Does the refresh work on the Power BI Service?

Yes it refreshes, though the visual didn't reflect the new data until I went into edit mode (within service) and selected refresh.  

 

jrieman_0-1725658849446.png

 

lbendlin
Super User
Super User

Are you using Query Folding?  Are you using native queries?

I believe folding.  Simple select * against data warehouse table.   When I right click 'Source' under APPLIED STEPS, view native query is greyed out.  I think that indicates I'm folding?  

 

jrieman_0-1725570146771.png

 

unfortunately it (mostly) means the opposite.  You can only be certain though when you run the query diagnostics.  Sometimes the "View native query"  is greyed out but the diagnostics still show a folded query call.

 

Understanding query evaluation and query folding in Power Query - Power Query | Microsoft Learn

 

Are you crafting your own queries?   Are you setting the "EnableFolding"  attribute?

Query folding on native queries - Power Query | Microsoft Learn

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.