Power BI Course
Query Parameters
A Power Query parameter is a named, reusable value that you can reference inside any query — in file paths, filter conditions, date ranges, server names, or anywhere a literal value would otherwise be hard-coded. Instead of editing M code every time an environment changes, you update one parameter and every query that uses it updates automatically. Parameters are the difference between a report that works in one place and a report that works everywhere.
What Parameters Solve
Creating a Parameter
Parameters are created from the Home tab in the Power Query Editor. Each parameter has a name, a type, and a current value. Optionally you can define a list of allowed values or set a minimum and maximum — useful when the parameter will be exposed to end users.
Parameter Types
| Type | Use for | Example value |
|---|---|---|
| Text | File paths, folder paths, server names, database names, filter text values | "C:\Data\Sales\" |
| Whole Number | Year, month number, row count limits, numeric thresholds | 2024 |
| Decimal Number | Revenue thresholds, percentage cutoffs, exchange rates | 0.15 |
| Date | Start date and end date for dynamic date range filtering | #date(2024,1,1) |
| True/False | Feature flags — include test data yes/no, apply currency conversion yes/no | false |
| Any | When the type may vary or is determined at runtime — use sparingly | any value |
Using Parameters in Queries
Once created, a parameter appears in the Queries pane under a Parameters group. Reference it in M code by name — no quotes, no brackets, just the parameter name. In the UI, the filter step dialogs offer a "Parameter" option instead of "Value" in their dropdowns.
// ── Pattern 1 — Dynamic file path ─────────────────────────────
// Parameter: FolderPath (Text) = "C:\Data\Sales\"
// Parameter: ReportYear (Whole Number) = 2024
Source = Csv.Document(
File.Contents(
FolderPath & "sales_" & Text.From(ReportYear) & ".csv"
),
[Delimiter=",", Encoding=65001]
)
// Loads: C:\Data\Sales\sales_2024.csv
// Change ReportYear to 2023 → loads sales_2023.csv automatically
// ── Pattern 2 — Filter rows by year parameter ──────────────────
// After Changed Type, filter OrderDate to the ReportYear
#"Filtered Year" = Table.SelectRows(
#"Changed Type",
each Date.Year([OrderDate]) = ReportYear
)
// Only rows where OrderDate falls in 2024 are loaded into the model
// ── Pattern 3 — Date range parameters ─────────────────────────
// Parameter: StartDate (Date) = #date(2024,1,1)
// Parameter: EndDate (Date) = #date(2024,12,31)
#"Filtered Range" = Table.SelectRows(
#"Changed Type",
each [OrderDate] >= StartDate and [OrderDate] <= EndDate
)
// ── Pattern 4 — Server and database parameters ─────────────────
// Parameter: ServerName (Text) = "prod-sql-01"
// Parameter: DatabaseName (Text) = "SalesDB"
Source = Sql.Database(ServerName, DatabaseName)
// Switch to dev: change ServerName to "dev-sql-01"
// All queries in the file repoint simultaneously
// ── Pattern 5 — Revenue threshold filter ──────────────────────
// Parameter: MinRevenue (Decimal Number) = 100.0
#"Filtered Revenue" = Table.SelectRows(
#"Changed Type",
each [Revenue] >= MinRevenue
)
| OrderID | OrderDate |
|---|---|
| 1001 | 2024-01-05 |
| 1003 | 2024-02-03 |
| 1005 | 2024-02-20 |
| OrderID | OrderDate |
|---|---|
| 1002 | 2023-11-18 |
| 1004 | 2023-12-14 |
Editing Parameters — Two Ways
Binding a Parameter to a Query Cell — What If Parameters
For advanced scenarios, a parameter can be bound to a value returned by another query — a technique called a "What If" parameter when combined with a DAX measure, or simply a query-driven parameter when the source is a Power Query table. This allows parameters to be driven by data rather than set manually.
// Pattern — parameter driven by the latest date in the source
// Step 1: Create a query called LatestOrderDate that returns a date scalar
let
Source = Orders,
MaxDate = List.Max(Source[OrderDate])
in
MaxDate // returns a single date value, e.g. #date(2024,2,20)
// Step 2: Create a Date parameter called EndDate
// In the parameter dialog, set Suggested Values to "Query"
// and select LatestOrderDate as the source query
// Current Value is now driven by the query — updates on refresh
// Step 3: Use EndDate in the Calendar table
let
StartDate = #date(Date.Year(EndDate), 1, 1),
EndYear = #date(Date.Year(EndDate), 12, 31),
DateCount = Duration.Days(EndYear - StartDate) + 1,
DateList = List.Dates(StartDate, DateCount, #duration(1,0,0,0))
// ... rest of calendar build
in
DateList
Combining Parameters with Folder-Based File Loading
One of the most powerful parameter patterns is combining a FolderPath parameter with the Folder connector. Power Query reads every file in the folder, appends them, and the parameter controls which folder to point at — instantly switching between a dev folder, a UAT folder, and a production folder with one value change.
// Parameter: FolderPath (Text) = "C:\Data\Production\Sales\"
// Query: AllSalesFiles — loads and appends every CSV in the folder
let
Source = Folder.Files(FolderPath),
// Keep only CSV files
CSVFiles = Table.SelectRows(
Source,
each Text.EndsWith([Name], ".csv")
),
// Add a column that parses each file
AddContent = Table.AddColumn(
CSVFiles,
"Data",
each Csv.Document([Content], [Delimiter=",", Encoding=65001])
),
// Expand all parsed tables into one
Expanded = Table.ExpandTableColumn(
AddContent,
"Data",
Table.ColumnNames(AddContent{0}[Data])
)
in
Expanded
// To switch from Production to UAT:
// Change FolderPath to "C:\Data\UAT\Sales\"
// Click Refresh — all files from the UAT folder load instead
// No other M code changes anywhere in the file
Parameters vs Hard-Coded Values — When to Use Each
| Value in the query | Make it a parameter? | Reason |
|---|---|---|
| File path or folder path | Always | Changes between machines, environments, and users — never hard-code a path |
| Server / database name | Always | Dev, UAT, and prod servers have different names — parameterise from day one |
| Report year or date range | Yes, if it changes periodically | Annual rollover requires no code editing when driven by a parameter |
| Revenue threshold for a filter | Yes, if business may change it | Parameters make business rules visible and adjustable without touching M code |
| Column name in a rename step | No | Column names are structural — they should be fixed in the cleaning step, not parameterised |
| Rounding precision (2 dp) | Usually no | A fixed business rule — unlikely to change and adding a parameter adds complexity without benefit |
Teacher's Note: The discipline of parameterising file paths and server names from the very first query you build is one of the highest-return habits in Power BI development. It costs about thirty seconds to create a FolderPath parameter. Not having one costs thirty minutes of debugging when a colleague opens the file on a different machine and every query fails with a "file not found" error. Make it a rule: if a value in your M code is specific to your machine, your environment, or this month — it is a parameter.
Practice
Practice 1 of 3
To view and change parameter values directly in the main Power BI Desktop window without opening the Power Query Editor, you go to Home → Transform Data dropdown → ___ Parameters.
Practice 2 of 3
A parameter is referenced in M code by its name with no quotes and no square brackets — for example, a Text parameter called FolderPath is used as Folder.Files(___).
Practice 3 of 3
Values that change between development, UAT, and production environments — such as server names and database names — should ___ be parameterised from the start of a project rather than hard-coded.
Lesson Quiz
Quiz 1 of 3
You share a Power BI file with a colleague. Their machine has a different username so the file path "C:\Users\alice\Data\sales.csv" does not exist on their machine. What is the correct fix and how do you prevent this problem in future files?
Quiz 2 of 3
You have a ReportYear parameter (Whole Number = 2024) and use it in a filter step: each Date.Year([OrderDate]) = ReportYear. You change ReportYear to 2023 and click Refresh. What happens to the loaded data?
Quiz 3 of 3
You want a parameter's current value to automatically update to the latest date in the Orders table on every refresh, rather than being set manually. Which approach achieves this?
Next up — Lesson 30 covers the M Language in depth, moving beyond individual functions to understand the full let…in structure, how queries reference each other, functions as first-class values, and the patterns that make complex transformations readable and maintainable.