Power Query – Automation and Parameters: Difference between revisions

From Training Material
Jump to navigation Jump to search
No edit summary
Line 31: Line 31:
You can reference parameters directly in the formula bar or Advanced Editor. Example:
You can reference parameters directly in the formula bar or Advanced Editor. Example:


<syntaxhighlight lang="m">
 
= Table.SelectRows(Source, each [Currency] = TargetCurrency)
= Table.SelectRows(Source, each [Currency] = TargetCurrency)
</syntaxhighlight>


== Using Parameters for File Paths ==
== Using Parameters for File Paths ==

Revision as of 09:14, 19 June 2025

Module 4: Automation and Parameters

Objective

In this module, you'll learn how to automate tasks using query parameters and load data dynamically.

Files Used

What Are Parameters?

Parameters let you store a value (like a currency code or file path) and reuse it in queries. They’re useful for automating imports and applying dynamic filters.

Creating a Parameter

Steps:

  1. In Power Query Editor, go to the Home tab → Manage ParametersNew Parameter
  2. Fill in the fields:
    • Name: e.g. `TargetCurrency`
    • Type: Text
    • Suggested Values: Any value (or a list, if preferred)
    • Current Value: e.g. `EUR`
  3. Click OK

Using a Parameter in a Filter

Steps:

  1. Load ExchangeRates.xlsx into Power Query
  2. Select the column Currency
  3. Go to the Home tab → Keep RowsKeep Rows Where...
  4. Choose: Column Currency equals parameter TargetCurrency

Using a Parameter in M Code

You can reference parameters directly in the formula bar or Advanced Editor. Example:


= Table.SelectRows(Source, each [Currency] = TargetCurrency)

Using Parameters for File Paths

Scenario: You want to dynamically load a file based on a path stored as a parameter.

Steps:

  1. Create a Text parameter, e.g. `FilePath`
  2. Go to the Home tab → New SourceExcel Workbook
  3. In the file dialog, use the value from the parameter
  4. If needed, open the Advanced Editor and replace static path with `FilePath`

Automating Folder Imports

Steps:

  1. Go to the Data tab → Get DataFrom FileFrom Folder
  2. Select a folder containing multiple files (e.g. sales reports)
  3. Click Transform Data
  4. Power Query will open a preview — click CombineCombine & Transform Data
  5. Use a parameter for the folder path if needed (replace in Advanced Editor or via formula bar)


→ Continue to Module 5: Power Pivot Overview


Return to Main Page