Fatskills
Practice. Master. Repeat.
Study Guide: TECH **Power BI Parameters & Dynamic Data Sources: Zero-Fluff Study Guide**
Source: https://www.fatskills.com/data-science/chapter/tech-power-bi-parameters-dynamic-data-sources-zero-fluff-study-guide

TECH **Power BI Parameters & Dynamic Data Sources: Zero-Fluff Study Guide**

By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.

⏱️ ~8 min read

Power BI Parameters & Dynamic Data Sources: Zero-Fluff Study Guide

(For real projects & PL-300 exam prep)


1. What This Is & Why It Matters

Parameters in Power BI are variables you define to control queries, filters, or data sources dynamically. Dynamic data sources let you change connection details (e.g., server names, file paths, or API endpoints) without editing the PBIX file manually.

Why This Matters in Production

  • Avoid hardcoding: If your SQL server moves from dev-sql to prod-sql, you shouldn’t open the PBIX file to update the connection. Parameters let you switch environments with a dropdown.
  • Deploy once, reuse everywhere: A single report can pull data from different databases (e.g., Sales_EU, Sales_US) based on user selection.
  • Automate refreshes: Dynamic data sources work with Power BI Gateway, so scheduled refreshes don’t break when paths or credentials change.
  • Security: Store sensitive connection strings in parameters (encrypted in the PBIX) instead of hardcoding them in M queries.

Real-World Scenario

You’re a BI analyst at a retail company. Your team maintains three identical reports (Dev, Test, Prod) that connect to different SQL databases. Every time a change is needed, you manually edit each PBIX file to point to the correct server. This is error-prone and unscalable.

Solution: Use parameters to dynamically switch between Dev-SQL, Test-SQL, and Prod-SQL with a single dropdown. Deploy one PBIX file, and let users (or the gateway) select the environment.


2. Core Concepts & Components

Term Definition Production Insight
Parameter A user-defined variable in Power Query (M) that stores values (text, number, list). Always use descriptive names (e.g., ServerName instead of Param1).
Query Parameter A parameter used inside a Power Query (M) step to filter or transform data. Parameters can be referenced in SQL queries, API URLs, or file paths.
Dynamic Data Source A data source whose connection details (server, path, credentials) change based on a parameter. Never hardcode credentials—use parameters + Power BI Gateway for secure refreshes.
M Language Power Query’s formula language (used to define parameters and dynamic sources). Learn basic M syntax (let, in, if, Text.Combine) to debug dynamic queries.
Power BI Gateway On-premises software that enables scheduled refreshes for dynamic data sources. Gateway must be configured with the correct data source permissions.
Static vs. Dynamic Static = hardcoded (e.g., Source = Sql.Database("prod-sql", "Sales")). Dynamic = parameter-driven (e.g., Source = Sql.Database(ServerName, "Sales")). Dynamic sources break if parameters aren’t passed correctly during refresh.
List Parameter A parameter with predefined values (e.g., ["Dev", "Test", "Prod"]). Use lists for dropdowns in reports (e.g., let users select an environment).
Credential Handling Storing usernames/passwords securely (via Power BI Service or Gateway). Never store passwords in M queries—use Power BI Service or Gateway instead.


3. Step-by-Step: Build a Dynamic SQL Data Source


Prerequisites

  • Power BI Desktop (latest version).
  • Access to two SQL databases (e.g., Dev-SQL and Prod-SQL) with identical schemas.
  • Basic familiarity with Power Query (M) and SQL.

Goal

Create a report that connects to either Dev-SQL or Prod-SQL based on a parameter dropdown.


Step 1: Create a Parameter for the Server Name

  1. Open Power BI Desktop.
  2. Go to HomeTransform DataTransform Data (opens Power Query Editor).
  3. In Power Query, go to HomeManage ParametersNew Parameter.
  4. Configure the parameter:
  5. Name: ServerName
  6. Type: Text
  7. Suggested Values: List of values
  8. List of values: ["dev-sql.company.com", "prod-sql.company.com"]
  9. Default Value: dev-sql.company.com
  10. Click OK.

Why?
This creates a dropdown in your report to switch between servers.


Step 2: Create a Dynamic SQL Data Source

  1. In Power Query, go to HomeNew SourceSQL Server.
  2. In the SQL Server dialog:
  3. Server: Enter dev-sql.company.com (temporary placeholder).
  4. Database: Enter your database name (e.g., SalesDB).
  5. Data Connectivity Mode: Import (or DirectQuery if needed).
  6. Click OK.
  7. Power Query will generate an M query like this:
    powerquery-m
    let
    Source = Sql.Database("dev-sql.company.com", "SalesDB")
    in
    Source
  8. Replace the hardcoded server name with your parameter:
    powerquery-m
    let
    Source = Sql.Database(ServerName, "SalesDB")
    in
    Source
  9. Click Close & Apply.

Why?
Now the data source dynamically uses the ServerName parameter.


Step 3: Add a Dropdown to Switch Servers

  1. In Power BI Desktop, go to the Report view.
  2. Add a Slicer visual to the canvas.
  3. Drag the ServerName parameter into the slicer.
  4. Test it: Select prod-sql.company.com from the dropdown. The data should refresh automatically.

Why?
Users can now switch environments without editing the PBIX file.


Step 4: Publish to Power BI Service & Configure Gateway

  1. Publish the report to Power BI Service.
  2. Go to the dataset settings in Power BI Service.
  3. Under Data Source Credentials, click Edit Credentials.
  4. Select OAuth2 (or Database if using SQL auth) and sign in.
  5. If using a Power BI Gateway:
  6. Install and configure the gateway.
  7. In dataset settings, map the data source to the gateway.
  8. Ensure the gateway has permissions to both dev-sql and prod-sql.

Why?
Scheduled refreshes will now work dynamically.


Step 5: Test Scheduled Refresh

  1. In Power BI Service, go to the dataset → SettingsScheduled Refresh.
  2. Enable refresh and set a schedule.
  3. Manually trigger a refresh and check the logs for errors.

Troubleshooting: - If refresh fails, check: - Gateway is online.
- Credentials are correct for both servers.
- Firewall allows connections from the gateway.


4. ? Production-Ready Best Practices


Security

  • Never hardcode credentials in M queries. Use:
  • Power BI Service’s data source credentials.
  • Power BI Gateway for on-premises data.
  • Restrict parameter values to a predefined list (e.g., only allow Dev, Test, Prod).
  • Use service accounts (not personal logins) for data sources.

Cost Optimization

  • Dynamic data sources reduce PBIX files: One report instead of three = less storage and maintenance.
  • Use DirectQuery sparingly: Dynamic sources with DirectQuery can slow down reports if overused.

Reliability & Maintainability

  • Name parameters clearly: ServerName > Param1.
  • Document parameters: Add a text box in the report explaining what each parameter does.
  • Test failover: Simulate a server outage by changing the parameter to an invalid value and verify error handling.

Observability

  • Monitor refresh failures: Set up alerts in Power BI Service for failed refreshes.
  • Log parameter changes: If using Power BI Premium, log parameter values in Power BI Audit Logs.


5. ⚠️ Common Mistakes & Traps

Mistake Symptom Fix/Prevention
Hardcoding credentials in M Refresh fails in Power BI Service (credentials not found). Use Power BI Service or Gateway for credentials.
Not testing dynamic sources Report works in Desktop but fails in Service after publishing. Always test dynamic sources in Power BI Service before deploying.
Using DirectQuery with parameters Report slows to a crawl when switching parameters. Use Import mode for dynamic sources unless DirectQuery is absolutely needed.
Forgetting gateway permissions Scheduled refresh fails with "gateway not configured" error. Map the data source to the gateway in Power BI Service.
Parameter values not in list Users can enter invalid server names (e.g., prod-sql.typo.com). Use List of values for parameters to restrict inputs.


6. ? Exam/Certification Focus (PL-300)


Typical Question Patterns

  1. Scenario-based: "You need to deploy a report that connects to Dev, Test, and Prod SQL databases. What’s the most maintainable approach?"
  2. Answer: Use parameters to dynamically switch data sources.
  3. Trap: Hardcoding server names in each PBIX file.

  4. M Query Syntax: "What’s the correct M syntax to reference a parameter named ServerName in a SQL query?"

  5. Answer: Sql.Database(ServerName, "DatabaseName")
  6. Trap: Forgetting to replace the hardcoded server name.

  7. Gateway Configuration: "Your dynamic data source refresh fails in Power BI Service. What’s the most likely cause?"

  8. Answer: The gateway isn’t configured for the dynamic data source.
  9. Trap: Assuming credentials are the issue (they’re usually handled separately).

  10. Parameter Types: "Which parameter type should you use to let users select from a list of environments?"

  11. Answer: List parameter with predefined values.
  12. Trap: Using a text parameter (allows invalid inputs).

7. ? Hands-On Challenge


Challenge

Create a Power BI report that: 1. Connects to two different Excel files (e.g., Sales_2023.xlsx and Sales_2024.xlsx).
2. Uses a parameter dropdown to switch between them.
3. Displays a table with data from the selected file.

Files to use: - Download Sales_2023.xlsx (placeholder).
- Download Sales_2024.xlsx (placeholder).

Solution

  1. Create a parameter FilePath with values:
    powerquery-m
    ["C:\Data\Sales_2023.xlsx", "C:\Data\Sales_2024.xlsx"]
  2. In Power Query, create a dynamic source:
    powerquery-m
    let
    Source = Excel.Workbook(File.Contents(FilePath), null, true)
    in
    Source
  3. Add a slicer for FilePath in the report.

Why it works: - File.Contents(FilePath) dynamically loads the file based on the parameter.
- The slicer lets users switch files without editing the PBIX.


8. ? Rapid-Reference Crib Sheet

Task Command/Syntax Notes
Create a parameter Home → Transform Data → Manage Parameters → New Parameter Use List of values for dropdowns.
Reference a parameter in M Sql.Database(ServerName, "Database") Replace hardcoded values with parameters.
Dynamic Excel file Excel.Workbook(File.Contents(FilePath)) Works for local files or SharePoint paths.
Dynamic API URL Web.Contents("https://api.company.com/" & ApiEndpoint) Use & to concatenate parameters.
Publish to Power BI Service Home → Publish → Select workspace Configure credentials in dataset settings.
Configure Gateway Power BI Service → Settings → Datasets → Gateway connection Map data sources to the gateway.
⚠️ Default parameter value Always set a default value (e.g., Dev instead of blank). Prevents errors on first load.
⚠️ DirectQuery with parameters Avoid unless necessary—can cause performance issues. Use Import mode for dynamic sources.
⚠️ Credentials in M Never store passwords in M queries. Use Power BI Service or Gateway.


9. ? Where to Go Next

  1. Microsoft Docs: Parameters in Power BI
  2. Official guide on dynamic M parameters.
  3. Power BI Gateway Documentation
  4. How to configure gateways for dynamic data sources.
  5. Guy in a Cube: Dynamic Data Sources
  6. Video walkthrough of dynamic SQL sources.
  7. PL-300 Exam Guide
  8. Official exam prep (focus on "Data Transformation" and "Data Modeling").


ADVERTISEMENT