Power Query – Automation and Parameters: Difference between revisions
												
				Jump to navigation
				Jump to search
				
No edit summary  | 
				|||
| Line 2: | Line 2: | ||
== Objective ==  | == Objective ==  | ||
Use parameters to automate queries and build dynamic data loading processes.  | |||
== Files Used ==  | == Files Used ==  | ||
* [[Media:ExchangeRates.xlsx|Download ExchangeRates.xlsx]]  | * [[Media:ExchangeRates.xlsx|Download ExchangeRates.xlsx]]  | ||
== Creating a Parameter ==  | == Creating a Parameter ==  | ||
'''Steps:'''  | '''Steps:'''  | ||
# In Power Query Editor  | # In Power Query Editor → '''Home''' tab → '''Manage Parameters''' → '''New Parameter'''  | ||
# Fill in   | # Fill in:  | ||
#* '''Name''': e.g. `TargetCurrency`  | #* '''Name''': e.g. `TargetCurrency`  | ||
#* '''Type''': Text  | #* '''Type''': Text  | ||
#* '''Current Value''': e.g. `EUR`  | #* '''Current Value''': e.g. `EUR`  | ||
# Click '''OK'''  | # Click '''OK'''  | ||
== Using a Parameter in   | == Using a Parameter in Filtering ==  | ||
'''Steps:'''  | '''Steps:'''  | ||
# Load '''ExchangeRates.xlsx''' into Power Query  | # Load '''ExchangeRates.xlsx''' into Power Query  | ||
# Select the column '''Currency'''  | # Select the column '''Currency'''  | ||
# Go to   | # Go to '''Home''' tab → '''Keep Rows''' → '''Keep Rows Where...'''  | ||
#   | # Set: ''Currency'' equals ''Parameter'' → choose `TargetCurrency`  | ||
== Using   | == Using Parameters in M Code ==  | ||
You can reference parameters directly in   | You can reference parameters directly in formulas:  | ||
<syntaxhighlight lang="m">  | |||
= Table.SelectRows(Source, each [Currency] = TargetCurrency)  | |||
</syntaxhighlight>  | |||
== Parameter for File Path ==  | |||
'''Scenario:''' Create a reusable query for loading Excel files.  | |||
'''Scenario:'''   | |||
'''Steps:'''  | '''Steps:'''  | ||
# Create a   | # Create a parameter `FilePath` (Type: Text)  | ||
# Go to   | # Go to '''Home''' tab → '''New Source''' → '''Excel Workbook'''  | ||
# In   | # In file path dialog, paste the value from the parameter  | ||
#   | # Or: go to Advanced Editor and replace path with `FilePath`  | ||
== Automating Folder Imports ==  | == Automating Folder Imports ==  | ||
'''Steps:'''  | '''Steps:'''  | ||
# Go to   | # Go to '''Data''' tab → '''Get Data''' → '''From File''' → '''From Folder'''  | ||
# Select a folder   | # Select a folder (e.g. with sales data)  | ||
# Click '''Transform Data'''  | # Click '''Transform Data'''  | ||
# Power Query   | # In Power Query Editor, click '''Combine''' → '''Combine & Transform Data'''  | ||
# Use a parameter for   | # Use a parameter for folder path if needed  | ||
== Additional Exercise: Parameterized Currency Filter ==  | |||
'''Goal:''' Build a flexible report that shows exchange rates for one currency.  | |||
'''Steps:'''  | |||
# Load '''ExchangeRates.xlsx'''  | |||
# Create a `TargetCurrency` parameter (e.g. "USD")  | |||
# Use it to filter the rows  | |||
# Load the result into a worksheet  | |||
== Extension: Combine Parameters and Folder Query ==  | |||
'''Goal:''' Allow the user to set a folder path dynamically.  | |||
'''Steps:'''  | |||
# Create parameter `FolderPath`  | |||
# Use it in '''From Folder''' source  | |||
# Refresh the query after changing parameter value  | |||
# Load combined data to Excel sheet  | |||
----  | |||
→ Continue to [[Power Query – Power Pivot Overview|Module 5: Power Pivot Overview]]  | |||
Return to [[Power_Query_–_Basic|Main Page]]  | Return to [[Power_Query_–_Basic|Main Page]]  | ||
Revision as of 09:47, 19 June 2025
Module 4: Automation and Parameters
Objective
Use parameters to automate queries and build dynamic data loading processes.
Files Used
Creating a Parameter
Steps:
- In Power Query Editor → Home tab → Manage Parameters → New Parameter
 - Fill in:
- Name: e.g. `TargetCurrency`
 - Type: Text
 - Current Value: e.g. `EUR`
 
 - Click OK
 
Using a Parameter in Filtering
Steps:
- Load ExchangeRates.xlsx into Power Query
 - Select the column Currency
 - Go to Home tab → Keep Rows → Keep Rows Where...
 - Set: Currency equals Parameter → choose `TargetCurrency`
 
Using Parameters in M Code
You can reference parameters directly in formulas:
= Table.SelectRows(Source, each [Currency] = TargetCurrency)Parameter for File Path
Scenario: Create a reusable query for loading Excel files.
Steps:
- Create a parameter `FilePath` (Type: Text)
 - Go to Home tab → New Source → Excel Workbook
 - In file path dialog, paste the value from the parameter
 - Or: go to Advanced Editor and replace path with `FilePath`
 
Automating Folder Imports
Steps:
- Go to Data tab → Get Data → From File → From Folder
 - Select a folder (e.g. with sales data)
 - Click Transform Data
 - In Power Query Editor, click Combine → Combine & Transform Data
 - Use a parameter for folder path if needed
 
Additional Exercise: Parameterized Currency Filter
Goal: Build a flexible report that shows exchange rates for one currency.
Steps:
- Load ExchangeRates.xlsx
 - Create a `TargetCurrency` parameter (e.g. "USD")
 - Use it to filter the rows
 - Load the result into a worksheet
 
Extension: Combine Parameters and Folder Query
Goal: Allow the user to set a folder path dynamically.
Steps:
- Create parameter `FolderPath`
 - Use it in From Folder source
 - Refresh the query after changing parameter value
 - Load combined data to Excel sheet
 
→ Continue to Module 5: Power Pivot Overview
Return to Main Page