top of page
Antares Studio Games Icon_Small.png

The Antares Alien

Power BI   |  DAX

Writer's pictureBrent Jones

Power BI: Ultimate Solution to Parameters and Changing Data Sources


Space...

Changing a data source is done on the Power Query side of Power BI. This can be a bit of a hassle as you need to open up the Power Query editor and...

1. Find the query

2. Go to the "Source" step

3. Then finally change the source

Changing a Data Source

Creating a Parameter

We can make this a bit easier by creating a parameter. This will allow us to simply select a data source from a pre-existing list directly - without having to go into Power Query.

1. Make the Parameter

To begin, click on the "New Parameter" button in Power Query:

New Parameter

A new window will pop up where you can create your parameter. For this example, my sources are different years of sales data.

List Parameter

You can choose a default value and a current value for the parameter. It's important to have a default value, because if a user ends up not choosing a value later on, Power Query will try to get data from a source that doesn't exist and subsequently fail.

2. Insert the Parameter in the Source

Next we need to change a bit of the Power Query 'M' code. Don't worry, it's simple! First, click on the "Source" step. You'll see the data source's full path being referenced in the code.

Data Source Path

The parameter we just created will replace the last part of the path, in this case the "2015 Sales.xlsx" part. All we need to do is replace it with:

" & #"Data Sources"

If you name your parameter something else, you need to use that name. For example, of your parameter name is "SQL DB", you'll use:

" & #"SQL DB"

Hit enter and the query should refresh without any errors. If you do get an error, check to make sure the names you entered in your parameter list match exactly with the sources.

You're Done!

Now you can easily change the data source from the Power BI report window. Just click on "Edit Queries" -> "Edit Parameters":