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

Dynamically change data source from SQL database

Dear everyone,

 

I have several tables in SQL databases, for example: table1, table2, table3, table4. All are at the same server, same database, share the same format, same number and title of columns.

 

I want to import those table from SQL server, customize them with SQL Scripts.

 

Then I want to have a slicer visual which contains the list of all tables

Then I want to create a function to change data source dynamically, import different table to power bi desktop when I select a table name from slicer.

Is that possible?

Can you please help with an example?

Many thanks in advance!
Cindy

1 ACCEPTED SOLUTION
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @Cindy,

 

Some additions to the wonderful post of @ImkeF. The feature changing parameters in the Service is on the way. 

Dynamically_change_data_source_from_SQL_database

 

Another easier workaround is changing the parameters directly without a slicer.

Dynamically_change_data_source_from_SQL_database2

 

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @Cindy,

 

Some additions to the wonderful post of @ImkeF. The feature changing parameters in the Service is on the way. 

Dynamically_change_data_source_from_SQL_database

 

Another easier workaround is changing the parameters directly without a slicer.

Dynamically_change_data_source_from_SQL_database2

 

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ImkeF
Super User
Super User

It's a bit of a hack on only works in Power BI Desktop, so not in the service: http://www.thebiccountant.com/2017/03/22/use-slicers-for-query-parameters-in-powerbi/

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

A different option would be to always load all tables into one big table with an additional column indicating the source.

The users can then do the same "source-selection" on the canvas and the data will be dynamically filtered instantly without having to refresh again.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Dear Imke,

Thanks very much for your solution. The problem is tables on SQL server are generated on monthly basis only. It means that, we only have tables up till present, and no future tables. For example this month is April 2018, then there is no table for May 2018.

It’s fine if it’s only work on power bi desktop. My idea is that we don’t need to go back to advanced editor to edit the query (change month number) every much.

Cheers,
Cindy

Especially with monthly tables I'd personally choose the large consolidated table-version instead.

Are you aware of parameters in Power BI? You can change them from the canvas-view as well without having to hack into your model.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

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.