Creating and Modifying Parameters

Earn 25 points (50 with Pro) in two steps

  1. ① Read through the lesson — each section gets a ✓ as you scroll through it.
  2. ② When every section has a ✓, tap Complete lesson.

0 of 11 read · keep scrolling

✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro

Creating and Modifying Parameters

Imagine you have built a complex data transformation pipeline that connects to a specific database on a local server. Your report works perfectly, but now your company is migrating that data to a cloud-based SQL server. Without parameters, you would have to open every single query, find the connection string, and manually update the server address. If you have fifty queries, you have fifty opportunities to make a typo and break the report.

Parameters solve this problem by acting as placeholders. Instead of hardcoding a specific value—like a server name, a file path, or a date range—directly into your query, you create a named variable. You then tell your query to look at that variable whenever it needs that specific piece of information. This single change transforms your data model from a rigid, brittle structure into a flexible, reusable asset. In this lesson, we will explore how to create, manage, and implement parameters to make your data preparation process more efficient and professional.

Not read yet

Understanding the Role of Parameters

In the context of data preparation, a parameter is a way to store a value that can be easily changed. Think of it like a remote control for your data queries. You define the parameter once, and then you can reference it in multiple places throughout your data transformation steps. When you change the value of the parameter, every query that references it updates automatically.

This is particularly useful in three main scenarios. First, it helps manage different environments. You might have a "Development" server and a "Production" server. By using a parameter for the server name, you can switch the entire report from one environment to the other by changing a single text box. Second, it helps with data volume management. If you are working with millions of rows, you can use a parameter to filter the data to just the last month while you are designing the report, then switch it to "All Time" once you are ready to publish. Third, parameters enable the creation of templates. You can build a standard report for one department and, by changing a "DepartmentID" parameter, generate the same report for a different department in seconds.

Callout: Parameters vs. Slicers It is common for beginners to confuse parameters with slicers. A Slicer is a visual element on a report page that allows an end-user to filter data that has already been loaded into the model. A Parameter is used during the data preparation phase (the "Get Data" or "Power Query" stage). Parameters define what data is loaded or how the connection is made before the data ever reaches the report visuals.

Not read yet

Step-by-Step: Creating Your First Parameter

Creating a parameter is a straightforward process, but it requires careful attention to data types. Most modern data tools, like Power BI or Excel’s Power Query, provide a dedicated interface for this.

1. Access the Parameter Manager

In your data transformation editor, look for a button labeled "Manage Parameters." Clicking this will open a dialog box where you can view existing parameters or create new ones.

2. Define the Basic Properties

When you click "New," you will need to provide several pieces of information:

  • Name: Give the parameter a clear, descriptive name. Avoid spaces if possible; use CamelCase or underscores (e.g., ServerName or p_StartDate).
  • Description: This is often overlooked but critical. Explain what the parameter does so that a colleague (or you, six months from now) understands why it exists.
  • Required: Check this box if the query cannot run without a value. Most connection-based parameters should be required.

3. Choose the Data Type

The data type must match the context where the parameter will be used. If you are using a parameter to filter a Date column, the parameter must be set to the "Date" or "Date/Time" type. If it is for a server name, use "Text." Choosing the wrong data type is one of the most common causes of query errors.

4. Set Suggested Values

You have three main options for how the parameter value can be entered:

  • Any Value: The user can type anything into a text box. This is flexible but prone to errors.
  • List of Values: You provide a hardcoded list of options. The user picks from a dropdown menu. This is great for things like "Environment" (Dev, Test, Prod).
  • Query: This is an advanced and powerful option. The list of choices for the parameter is generated by another query. For example, you could have a query that pulls a list of all active "Project IDs" from a database, and the parameter dropdown will always be up-to-date.

5. Set the Current Value

Before you can save the parameter, you must provide a starting value. This is the value the queries will use immediately upon creation.

Note: When naming parameters, many professionals use a prefix like p or parm. For example, p_FileDirectory. This makes it immediately obvious in your code which items are parameters and which are standard table names.

Not read yet

Implementing Parameters in Data Connections

Once a parameter is created, it doesn't do anything until you reference it in a query. The most common use case is dynamic data sourcing. Let's look at how to replace a hardcoded file path with a parameter.

Example: Dynamic File Paths

Imagine you are importing a CSV file from C:\Reports\2023\SalesData.csv. If you move that folder, your query breaks. Instead, create a parameter named p_FolderPath with the value C:\Reports\2023\.

In your query's source step, the code might originally look like this: Source = Csv.Document(File.Contents("C:\Reports\2023\SalesData.csv"), [Delimiter=","])

You would modify it to use the parameter like this: Source = Csv.Document(File.Contents(p_FolderPath & "SalesData.csv"), [Delimiter=","])

By using the ampersand (&) to join the parameter and the filename, you’ve made the folder location dynamic. If you move your data to a "2024" folder, you only update the parameter value, and the query continues to function perfectly.

Example: Server and Database Connections

For enterprise SQL databases, you often have different server addresses for testing and production. You can create two parameters: p_Server and p_Database. When you go to "Get Data" and select SQL Server, instead of typing the server name, you can click the icon in the text box to switch from "Text" input to "Parameter" input. Select your p_Server parameter from the dropdown. This ensures that your connection logic is centralized.

Not read yet

Modifying and Updating Parameters

Requirements change, and you will eventually need to modify your parameters. This can be done in two ways: through the management interface or, in some cases, directly via the report's main interface.

Changing the Structure

If you need to change a parameter from a "Text" type to a "List of Values," you must return to the "Manage Parameters" dialog. Here, you can add new items to a list, change the default value, or update the description. Be careful when changing data types; if a query expects a number and you change the parameter to text, the query will throw an error.

Updating the Value

In many BI tools, you don't need to enter the "Transform Data" or "Power Query" editor just to change a parameter's value. There is often an "Edit Parameters" option in the main menu. This allows users to quickly swap out a date or a server name without seeing the underlying code or transformation steps.

Bulk Updates with Query-Based Parameters

If you are using a "Query" as the source for your parameter's suggested values, you don't manually modify the list. Instead, you modify the source data. For instance, if your parameter is a list of "Store Locations" pulled from an Excel file, adding a new store to that Excel file and refreshing the data will automatically update the parameter's dropdown list.

Warning: Be cautious when deleting parameters. Most tools do not have an "undo" for parameter deletion that automatically fixes the queries that used them. If you delete a parameter that is referenced in five queries, all five queries will immediately break and show an error message stating that the name was not recognized.

Not read yet

Advanced Use Case: Filtering with Parameters

One of the most effective ways to use parameters is to control the volume of data being imported. This is often called "Range Filtering" or "Incremental Loading Preparation."

Suppose you have a database with ten years of sales data, but you usually only need to report on the last two years. You can create a parameter called p_MinDate. In your query, you apply a filter to the OrderDate column where the date must be greater than or equal to p_MinDate.

The Power of Query Folding

When you use a parameter to filter data from a relational database (like SQL Server), the tool can often "fold" that parameter into the SQL statement sent to the server.

Without Parameter (Hardcoded): SELECT * FROM Sales WHERE OrderDate >= '2021-01-01'

With Parameter: The tool sends the value of p_MinDate to the server dynamically. This means the server does the filtering work, and only the necessary rows are sent over the network. This significantly improves performance compared to downloading all ten years of data and filtering it on your local machine.

Not read yet

Using Parameters in the "M" Language

For those who want to go beyond the graphical interface, parameters are simply variables in the Power Query formula language (known as M). Understanding how they appear in the code can help you troubleshoot complex issues.

A parameter is defined in its own script, but it is called by name in other scripts. Here is a simplified example of how a parameter looks when used in a custom function:

let
    // Reference the parameter 'p_TargetMargin'
    Source = SalesTable,
    CalculateMargin = Table.AddColumn(Source, "AboveTarget", each [Margin] > p_TargetMargin)
in
    CalculateMargin

In this snippet, p_TargetMargin is a parameter representing a decimal number (like 0.35). If the business decides the new target is 0.40, you update the parameter, and the "AboveTarget" column recalculates across all queries using this logic.

Comparison: Hardcoded Values vs. Parameters

Feature Hardcoded Values Parameters
Flexibility Low - must edit every query manually. High - update once, applies everywhere.
Portability Difficult - paths are tied to one machine. Easy - change one path parameter for new users.
User Experience Poor - requires technical knowledge to change. Good - easy "Edit Parameter" dialog for non-tech users.
Maintenance High - prone to typos and missed updates. Low - centralized management.
Security Risky - sensitive info might be scattered in code. Better - sensitive values are localized (though still visible).

Not read yet

Best Practices for Parameter Management

To keep your data models clean and professional, follow these industry-standard practices:

1. Centralize Your Connections

Always use parameters for Server Names, Database Names, and File Paths. Even if you think the location will never change, it almost always does. Moving from a local drive to a SharePoint site or a network drive is a common transition that is made painless by parameters.

2. Document Everything

Use the description field to specify the expected format. For a date parameter, you might write: "Format: YYYY-MM-DD. This controls the start date for the sales data import." This prevents other developers from entering data in a format that might cause errors.

3. Use Lists for Consistency

If a parameter only has a few valid options (like "North", "South", "East", "West"), use a "List of Values" instead of "Any Value." This prevents typos like "Nort" from breaking your filters.

4. Mind the Privacy Levels

When you combine data from different sources (like a SQL database and a parameter from an Excel file), you may encounter "Privacy Level" errors. This is a security feature that prevents data from one source being accidentally sent to another. Ensure your parameters and your data sources are set to the same privacy level (e.g., "Organizational") to avoid these "Formula.Firewall" errors.

5. Keep it Simple

Don't over-parameterize. If a value truly will never change (like the number of months in a year), there is no need for a parameter. Only parameterize values that provide strategic flexibility or help with environment management.

Not read yet

Common Pitfalls and How to Avoid Them

Even experienced data professionals run into trouble with parameters. Here are the most frequent mistakes:

Data Type Mismatches

This is the number one cause of parameter-related errors. If your parameter is a "Text" type but you are trying to use it to filter a "Decimal Number" column, the query will fail. Always double-check that the parameter type matches the column type it is interacting with.

Case Sensitivity

In many data languages (including M), "ServerName" and "servername" are different things. If you create a parameter called p_City but try to call it as p_city in your query code, you will get a "Name not recognized" error. Stick to a consistent casing convention.

Hardcoding Inside the Parameter

Sometimes people create a parameter but then type a specific value inside a custom column formula instead of referencing the parameter name.

  • Wrong: if [Sales] > 100 then "High" else "Low" (Where 100 should be the parameter).
  • Right: if [Sales] > p_Threshold then "High" else "Low". Always check your custom formulas to ensure you haven't left hardcoded values behind.

Forgetting to Update Before Publishing

If you use a parameter to limit data to 10 rows for fast testing, make sure you change it back to the full data amount before you publish the report to your team. It is a common mistake to send out a "Final Report" that only contains a handful of test records.

Callout: The "Template" Power Move You can save your work as a Template file (like a .PBIT in Power BI). When someone opens a template, the tool immediately prompts them to fill in the parameters. This is an incredible way to distribute tools to other departments. You provide the logic; they provide their specific Server Name or Department ID, and the report builds itself for their specific needs.

Not read yet

Real-World Scenario: The Regional Manager's Report

Let’s put everything together with a practical example. You are a data analyst for a national retail chain. You have been asked to create a report that can be used by 50 different regional managers. Each manager’s data is stored in a separate SQL database named after their region (e.g., Sales_North, Sales_South, etc.).

If you didn't use parameters, you would have to build 50 separate reports. Instead, you do the following:

  1. Create a Parameter: You name it p_RegionName. You set the "Suggested Values" to a "List of Values" containing "North", "South", "East", and "West".
  2. Connect to Data: When connecting to the SQL Server, you use the parameter to define the database name. In the connection dialog, you write Sales_ & p_RegionName.
  3. Apply Transformations: You build all your charts, clean the column names, and set up the logic once.
  4. Distribute: You save the report. When the North region manager opens it, they select "North" from the parameter dropdown. The query dynamically connects to Sales_North. When the South region manager opens the same file, they select "South," and the query connects to Sales_South.

By using one parameter, you have reduced your maintenance workload by 98%. If you need to add a new "Profit Margin" calculation, you add it to one file, not fifty.

Not read yet

Summary and Key Takeaways

Parameters are the foundation of scalable, maintainable data preparation. They move your logic away from "hardcoded" values and toward a "dynamic" system. By mastering parameters, you transition from someone who just "makes reports" to someone who "builds data systems."

As you move forward, remember these core principles:

  • Flexibility over Rigidity: Use parameters for any value that might change between users, environments, or time periods.
  • Consistency is Key: Use naming conventions and clear descriptions to make your parameters easy to understand for others.
  • Type Safety: Always ensure your parameter data type matches the data type of the column or function it is interacting with.
  • Performance Matters: Use parameters for filtering early in your query process to take advantage of query folding and reduce the load on your system.
  • Centralize Connections: Never hardcode a server name or file path; these are the most important candidates for parameterization.
  • Templates are Powerful: Use parameters to turn your reports into reusable templates that can be shared across your entire organization.

By implementing these strategies, you will save hours of tedious manual updates and create data models that are far more resilient to change. Parameters are a simple concept with profound implications for the quality and longevity of your data projects.

Not read yet

Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.